Skip to content

Instantly share code, notes, and snippets.

@Kroisse
Last active December 15, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kroisse/5211709 to your computer and use it in GitHub Desktop.
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.
>>>> 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