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 ncoghlan
Recipients Rhamphoryncus, klaas, ncoghlan
Date 2007-11-02.09:45:16
SpamBayes Score 0.011153664
Marked as misclassified No
Message-id <1193996718.45.0.539014502189.issue1705170@psf.upfronthosting.co.za>
In-reply-to
Content
Close, but not quite. The problem is that the 'value' argument may be
None if instantiation of the exception hasn't been forced before
__exit__ gets called.

>>> class TestWith(object):
...   def __enter__(self):
...     pass
...   def __exit__(self, exc_type, exc_value, exc_tb):
...     print exc_type, exc_value, exc_tb
...
>>> from __future__ import with_statement
>>> with TestWith(): iter([]).next()
...
<type 'exceptions.StopIteration'> None <traceback object at 0xb76bed4c>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration

That 'None' in the middle there is the problem - contextmanager.__exit__
needs to be detecting that and instantiating the passed in exception if
it isn't already instantiated. Something like the following at the start
of the else clause should do the trick:

  if value is None:
    value = type()
History
Date User Action Args
2007-11-02 09:45:18ncoghlansetspambayes_score: 0.0111537 -> 0.011153664
recipients: + ncoghlan, Rhamphoryncus, klaas
2007-11-02 09:45:18ncoghlansetspambayes_score: 0.0111537 -> 0.0111537
messageid: <1193996718.45.0.539014502189.issue1705170@psf.upfronthosting.co.za>
2007-11-02 09:45:18ncoghlanlinkissue1705170 messages
2007-11-02 09:45:16ncoghlancreate