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.

Author doerwalter
Recipients doerwalter, vstinner
Date 2013-11-14.17:43:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1384451011.57.0.628286278608.issue19585@psf.upfronthosting.co.za>
In-reply-to
Content
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'
History
Date User Action Args
2013-11-14 17:43:31doerwaltersetrecipients: + doerwalter, vstinner
2013-11-14 17:43:31doerwaltersetmessageid: <1384451011.57.0.628286278608.issue19585@psf.upfronthosting.co.za>
2013-11-14 17:43:31doerwalterlinkissue19585 messages
2013-11-14 17:43:31doerwaltercreate