Mike Klaas added the comment:

Verified on 2.5.0.  The problem stems from contextmanager.__exit__:

 def __exit__(self, type, value, traceback):
        if type is None:
            try:
                self.gen.next()
            except StopIteration:
                return
            else:
                raise RuntimeError("generator didn't stop")
        else:
            try:
                self.gen.throw(type, value, traceback)
                raise RuntimeError("generator didn't stop after throw
()")
            except StopIteration, exc:
                # Suppress the exception *unless* it's the same 
exception that
                # was passed to throw().  This prevents a StopIteration
                # raised inside the "with" statement from being 
suppressed
                return exc is not value
            except:
                # only re-raise if it's *not* the exception that was
                # passed to throw(), because __exit__() must not raise
                # an exception unless __exit__() itself failed.  But 
throw()
                # has to raise the exception to signal propagation, so 
this
                # fixes the impedance mismatch between the throw() 
protocol
                # and the __exit__() protocol.
                #
                if sys.exc_info()[1] is not value:
                    raise

Conjecture: internal StopIteration exceptions are always the same 
instance (PyExc_StopIteration) when propagated to python, invalidating 
the                 return exc is not value
check.

----------
nosy: +klaas

_____________________________________
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