[issue4806] Function calls taking a generator as star argument can mask TypeErrors in the generator

Martin Panter report at bugs.python.org
Mon Feb 15 04:04:18 EST 2016


Martin Panter added the comment:

Michel: I suspect your code doesn’t actually get up to handling any coroutines, and the problem is in your generator expression. What is “l”, and what are the items in it? The bug should already be fixed ready for the 3.5.2 and 3.6 releases, but I can produce this on 3.5.0:

>>> l = [None]
>>> f = (coro() for coro in l) 
>>> asyncio.gather(*f)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: gather() argument after * must be a sequence, not generator

In the current 3.6 code the bug is fixed:

>>> asyncio.gather(*f)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <genexpr>
TypeError: 'NoneType' object is not callable

The reason why the second call does nothing interesting is because the generator expression has already die because of the exception, and there is nothing left to iterate:

>>> remaining = [*f]
>>> remaining
[]
>>> asyncio.gather(*remaining)
<Future finished result=[]>

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4806>
_______________________________________


More information about the Python-bugs-list mailing list