Nick Coghlan added the comment:

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()

----------
nosy: +ncoghlan

_____________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1705170>
_____________________________________
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to