Skip to content

Instantly share code, notes, and snippets.

@Kroisse
Last active Dec 15, 2015
Embed
What would you like to do?
I think that CPython treats TypeError specially in the generator expression. So do PyPy.
>>>> 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
>>>>
>>> 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
>>>
>>> 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