Browse Source

Rename AsyncIterator.get to next to prevent shadowing.

pull/626/head
Rapptz 8 years ago
parent
commit
e0f02f1775
  1. 2
      discord/abc.py
  2. 20
      discord/iterators.py
  3. 2
      discord/reaction.py
  4. 15
      docs/api.rst

2
discord/abc.py

@ -872,7 +872,7 @@ class Messageable(metaclass=abc.ABCMeta):
iterator = channel.history(limit=200)
while True:
try:
message = yield from iterator.get()
message = yield from iterator.next()
except discord.NoMoreItems:
break
else:

20
discord/iterators.py

@ -56,7 +56,7 @@ class _AsyncIterator:
def find(self, predicate):
while True:
try:
elem = yield from self.get()
elem = yield from self.next()
except NoMoreItems:
return None
@ -75,7 +75,7 @@ class _AsyncIterator:
ret = []
while True:
try:
item = yield from self.get()
item = yield from self.next()
except NoMoreItems:
return ret
else:
@ -89,7 +89,7 @@ class _AsyncIterator:
@asyncio.coroutine
def __anext__(self):
try:
msg = yield from self.get()
msg = yield from self.next()
except NoMoreItems:
raise StopAsyncIteration()
else:
@ -104,9 +104,9 @@ class _MappedAsyncIterator(_AsyncIterator):
self.func = func
@asyncio.coroutine
def get(self):
def next(self):
# this raises NoMoreItems and will propagate appropriately
item = yield from self.iterator.get()
item = yield from self.iterator.next()
return (yield from maybe_coroutine(self.func, item))
class _FilteredAsyncIterator(_AsyncIterator):
@ -119,8 +119,8 @@ class _FilteredAsyncIterator(_AsyncIterator):
self.predicate = predicate
@asyncio.coroutine
def get(self):
getter = self.iterator.get
def next(self):
getter = self.iterator.next
pred = self.predicate
while True:
# propagate NoMoreItems similar to _MappedAsyncIterator
@ -143,7 +143,7 @@ class ReactionIterator(_AsyncIterator):
self.users = asyncio.Queue(loop=state.loop)
@asyncio.coroutine
def get(self):
def next(self):
if self.users.empty():
yield from self.fill_users()
@ -271,7 +271,7 @@ class HistoryIterator(_AsyncIterator):
self._retrieve_messages = self._retrieve_messages_before_strategy
@asyncio.coroutine
def get(self):
def next(self):
if self.messages.empty():
yield from self.fill_messages()
@ -437,7 +437,7 @@ class AuditLogIterator(_AsyncIterator):
return data.get('users', []), entries
@asyncio.coroutine
def get(self):
def next(self):
if self.entries.empty():
yield from self._fill()

2
discord/reaction.py

@ -137,7 +137,7 @@ class Reaction:
iterator = reaction.users()
while True:
try:
user = yield from iterator.get()
user = yield from iterator.next()
except discord.NoMoreItems:
break
else:

15
docs/api.rst

@ -1246,7 +1246,7 @@ If you are using 3.4 however, you will have to use the more verbose way: ::
iterator = channel.history() # or whatever returns an async iterator
while True:
try:
item = yield from iterator.get()
item = yield from iterator.next()
except discord.NoMoreItems:
break
@ -1259,6 +1259,19 @@ Certain utilities make working with async iterators easier, detailed below.
Represents the "AsyncIterator" concept. Note that no such class exists,
it is purely abstract.
.. container:: operations
.. describe:: async for x in y
Iterates over the contents of the async iterator. Note
that this is only available in Python 3.5 or higher.
.. method:: next()
Advances the iterator by one, if possible. If no more items are found
then this raises :exc:`NoMoreItems`.
.. method:: get(**attrs)
|coro|

Loading…
Cancel
Save