Message358333
>>> 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. |
|
Date |
User |
Action |
Args |
2019-12-13 15:19:37 | maggyero | set | recipients:
+ maggyero, gvanrossum, ncoghlan |
2019-12-13 15:19:37 | maggyero | set | messageid: <1576250377.83.0.345840572176.issue39037@roundup.psfhosted.org> |
2019-12-13 15:19:37 | maggyero | link | issue39037 messages |
2019-12-13 15:19:37 | maggyero | create | |
|