[New-bugs-announce] [issue27100] Attempting to use class with both __enter__ & __exit__ undefined yields __exit__ attribute error
Jonathan Ellington
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():
... pass
...
>>> with A():
... pass
...
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
files: with.patch
keywords: patch
messages: 266219
nosy: ellingtonjp, rhettinger
priority: normal
severity: normal
status: open
title: Attempting to use class with both __enter__ & __exit__ undefined yields __exit__ attribute error
type: behavior
Added file: http://bugs.python.org/file42962/with.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27100>
_______________________________________
More information about the New-bugs-announce
mailing list