Message202865
See http://bugs.python.org/issue18861 and the discussion started here: https://mail.python.org/pipermail/python-dev/2013-November/130155.html.
Basically it allows to add context information to a traceback without changing the type of the exception.
In the following example:
import itertools
', '.join(itertools.chain((str(i) for i in range(100)), [42]))
the join method itself adds context information to the TypeError:
Traceback (most recent call last):
File "hurz.py", line 2, in <module>
', '.join(itertools.chain((str(i) for i in range(100)), [42]))
TypeError: sequence item 100: expected str instance, int found
i.e. the "sequence item 100" is context information.
However when the exception occurs higher up in the call chain, no such context information is added:
import itertools
def foo(x):
return str(x+1)
', '.join(foo(x) for x in itertools.chain(range(100), [None]))
This gives:
Traceback (most recent call last):
File "hurz.py", line 6, in <module>
', '.join(foo(x) for x in itertools.chain(range(100), [None]))
File "hurz.py", line 6, in <genexpr>
', '.join(foo(x) for x in itertools.chain(range(100), [None]))
File "hurz.py", line 4, in foo
return str(x+1)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
With frame annotations the traceback might look like this:
Traceback (most recent call last):
File "hurz.py", line 6, in <module>
', '.join(foo(x) for x in itertools.chain(range(100), [None]))
File "hurz.py", line 6, in <genexpr>: sequence item 100
', '.join(foo(x) for x in itertools.chain(range(100), [None]))
File "hurz.py", line 4, in foo
return str(x+1)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' |
|
Date |
User |
Action |
Args |
2013-11-14 17:43:31 | doerwalter | set | recipients:
+ doerwalter, vstinner |
2013-11-14 17:43:31 | doerwalter | set | messageid: <1384451011.57.0.628286278608.issue19585@psf.upfronthosting.co.za> |
2013-11-14 17:43:31 | doerwalter | link | issue19585 messages |
2013-11-14 17:43:31 | doerwalter | create | |
|