Related issue: http://bugs.python.org/issue4806
Last active
December 15, 2015 05:49
-
-
Save Kroisse/5211709 to your computer and use it in GitHub Desktop.
I think that CPython treats TypeError specially in the generator expression. So do PyPy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>>> def f(a): raise TypeError | |
>>>> def do(*args): return args | |
>>>> do(*(f(i) for i in '123')) | |
Traceback (most recent call last): | |
File "<console>", line 1, in <module> | |
TypeError: argument after * must be a sequence, not generator | |
>>>> def f(a): raise LookupError | |
>>>> do(*(f(i) for i in '123')) | |
Traceback (most recent call last): | |
File "<console>", line 1, in <module> | |
File "<console>", line 1, in <genexpr> | |
File "<console>", line 1, in f | |
LookupError | |
>>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def f(a): | |
... raise Exception | |
... | |
>>> def seq(*args): | |
... return args | |
... | |
>>> seq(*(f(i) for i in 'asdf')) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 1, in <genexpr> | |
File "<stdin>", line 1, in f | |
Exception | |
>>> def f(a): | |
... raise TypeError | |
... | |
>>> seq(*(f(i) for i in 'asdf')) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: seq() argument after * must be a sequence, not generator | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def broken(a): raise TypeError | |
... | |
>>> def do(*args): return args | |
... | |
>>> do(*(broken(i) for i in 'asdf')) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: do() argument after * must be a sequence, not generator | |
>>> do(*map(broken, 'asdf')) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: do() argument after * must be a sequence, not map | |
>>> def f(a): raise Exception | |
... | |
>>> do(*map(f, 'asdf')) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 1, in f | |
Exception | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment