mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-05 06:01:02 +03:00
Handle negative limits gracefully in async generators
We rely on >= 0 for setting the batch size to use (which must be valid), so it makes sense to make negative limits equal 0. This is similar to how asyncio.sleep(negative) sleeps 0 seconds, despite the fact that time.sleep(negative) fails.
This commit is contained in:
parent
d508e58d49
commit
d02d0e2d5e
|
@ -37,7 +37,7 @@ class _ParticipantsIter(RequestIter):
|
|||
functions.channels.GetFullChannelRequest(entity)
|
||||
)).full_chat.participants_count
|
||||
|
||||
if self.limit == 0:
|
||||
if self.limit <= 0:
|
||||
raise StopAsyncIteration
|
||||
|
||||
self.seen = set()
|
||||
|
|
|
@ -18,7 +18,7 @@ class _DialogsIter(RequestIter):
|
|||
hash=0
|
||||
)
|
||||
|
||||
if self.limit == 0:
|
||||
if self.limit <= 0:
|
||||
# Special case, get a single dialog and determine count
|
||||
dialogs = await self.client(self.request)
|
||||
self.total = getattr(dialogs, 'count', len(dialogs.dialogs))
|
||||
|
|
|
@ -111,7 +111,7 @@ class _MessagesIter(RequestIter):
|
|||
hash=0
|
||||
)
|
||||
|
||||
if self.limit == 0:
|
||||
if self.limit <= 0:
|
||||
# No messages, but we still need to know the total message count
|
||||
result = await self.client(self.request)
|
||||
if isinstance(result, types.messages.MessagesNotModified):
|
||||
|
|
Loading…
Reference in New Issue
Block a user