homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Function call with * and generator hide exception raised by generator.
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Function calls taking a generator as star argument can mask TypeErrors in the generator
View: 4806
Assigned To: Nosy List: daniel.urban, eric.araujo, falsetru, martin.panter, ncoghlan
Priority: normal Keywords:

Created on 2011年04月28日 01:00 by falsetru, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (4)
msg134632 - (view) Author: Jeong-Min Lee (falsetru) Date: 2011年04月28日 01:00
Expected "TypeError: cannot concatenate 'str' and 'int' objects" exception raised, but got following result.
>>> def g():
... '1' + 0
... yield 1, 2
... yield 3, 4
...
>>> zip(*g())
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: zip() argument after * must be a sequence, not generator
>>> (lambda xs: 0)(*g())
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: <lambda>() argument after * must be a sequence, not generator
>>> list(*g())
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: type object argument after * must be a sequence, not generator
>>> list(g())
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "<stdin>", line 2, in g
TypeError: cannot concatenate 'str' and 'int' objects
msg134636 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2011年04月28日 02:53
It's not just hiding the real error, it's also saying something that isn't true. If you remove the deliberate error from the generator definition, it is clear that generators are perfectly acceptable as *arg inputs:
>>> def g(): yield 1, 2
... 
>>> list(*g())
[1, 2]
msg134665 - (view) Author: Jeong-Min Lee (falsetru) Date: 2011年04月28日 09:22
Some exceptions are reported correctly.
>>> def g():
... 1 / 0
... yield 1, 2
... yield 3, 4
... 
>>> zip(*g())
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "<stdin>", line 2, in g
ZeroDivisionError: integer division or modulo by zero
>>> def g():
... [][0]
... yield 1, 2
... yield 3, 4
... 
>>> zip(*g())
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "<stdin>", line 2, in g
IndexError: list index out of range
msg134712 - (view) Author: Daniel Urban (daniel.urban) * (Python triager) Date: 2011年04月28日 18:52
This may be the same/similar as issue4806 (which has a patch).
History
Date User Action Args
2022年04月11日 14:57:16adminsetgithub: 56153
2012年02月04日 02:06:33terry.reedysetstatus: open -> closed
resolution: duplicate
superseder: Function calls taking a generator as star argument can mask TypeErrors in the generator
2012年01月12日 04:41:00martin.pantersetnosy: + martin.panter
2011年04月28日 18:52:53daniel.urbansetnosy: + daniel.urban
messages: + msg134712
2011年04月28日 09:22:42falsetrusetmessages: + msg134665
2011年04月28日 03:05:28eric.araujosetnosy: + eric.araujo
2011年04月28日 02:53:22ncoghlansetnosy: + ncoghlan
messages: + msg134636
2011年04月28日 01:00:58falsetrusetversions: + Python 3.2, - Python 3.3
2011年04月28日 01:00:46falsetrucreate

AltStyle によって変換されたページ (->オリジナル) /