asyncio, Tulip issue 131: as_completed() and wait() now raises a TypeError if

the list of futures is not a list but a Future, Task or coroutine object
This commit is contained in:
Victor Stinner 2014-02-11 11:54:08 +01:00
parent 4e8d2f25e2
commit eb74876e99
2 changed files with 30 additions and 0 deletions

View file

@ -358,6 +358,8 @@ def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
Note: This does not raise TimeoutError! Futures that aren't done
when the timeout occurs are returned in the second set.
"""
if isinstance(fs, futures.Future) or iscoroutine(fs):
raise TypeError("expect a list of futures, not %s" % type(fs).__name__)
if not fs:
raise ValueError('Set of coroutines/Futures is empty.')
@ -474,6 +476,8 @@ def as_completed(fs, *, loop=None, timeout=None):
Note: The futures 'f' are not necessarily members of fs.
"""
if isinstance(fs, futures.Future) or iscoroutine(fs):
raise TypeError("expect a list of futures, not %s" % type(fs).__name__)
loop = loop if loop is not None else events.get_event_loop()
deadline = None if timeout is None else loop.time() + timeout
todo = {async(f, loop=loop) for f in set(fs)}