[New-bugs-announce] [issue27100] Attempting to use class with both __enter__ & __exit__ undefined yields __exit__ attribute error
report at bugs.python.org
Mon May 23 23:28:37 EDT 2016
New submission from Jonathan Ellington:
Attempting to use class that has both __exit__() and __enter__() undefined as a context manager yields an AttributeError referring to __exit__:
>>> class A():
>>> with A():
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: A instance has no attribute '__exit__'
Knowing that the 'with' statement should first execute __enter__, this is unexpected.
The patch ensures the attribute error refers to __enter__() when both methods are undefined.
components: Interpreter Core
nosy: ellingtonjp, rhettinger
title: Attempting to use class with both __enter__ & __exit__ undefined yields __exit__ attribute error
Added file: http://bugs.python.org/file42962/with.patch
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce