This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maggyero
Recipients gvanrossum, maggyero, ncoghlan
Date 2019-12-13.15:19:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576250377.83.0.345840572176.issue39037@roundup.psfhosted.org>
In-reply-to
Content
>>> class A: pass
    ... 
    >>> with A(): pass
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: __enter__

I expected `AttributeError: __exit__`, since PEP 343 states (https://www.python.org/dev/peps/pep-0343/#specification-the-with-statement):

> The details of the above translation are intended to prescribe the exact semantics. If either of the relevant methods are not found as expected, the interpreter will raise AttributeError, in the order that they are tried (__exit__, __enter__).

and the language documentation states (https://docs.python.org/3/reference/compound_stmts.html#the-with-statement):

> The execution of the with statement with one “item” proceeds as follows:
> 1. The context expression (the expression given in the with_item) is evaluated to obtain a context manager.
> 2. The context manager’s __exit__() is loaded for later use.
> 3. The context manager’s __enter__() method is invoked.
History
Date User Action Args
2019-12-13 15:19:37maggyerosetrecipients: + maggyero, gvanrossum, ncoghlan
2019-12-13 15:19:37maggyerosetmessageid: <1576250377.83.0.345840572176.issue39037@roundup.psfhosted.org>
2019-12-13 15:19:37maggyerolinkissue39037 messages
2019-12-13 15:19:37maggyerocreate