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 <rep...@bugs.python.org>
<http://bugs.python.org/issue27100>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to