File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -398,11 +398,13 @@ The execution of the :keyword:`with` statement with one "item" proceeds as follo
398
398
399
399
#. The context expression (the expression given in the :token: `with_item `) is
400
400
evaluated to obtain a context manager.
401
-
402
- #. The context manager's :meth: `__enter__ ` method is invoked .
401
+
402
+ #. The context manager's :meth: `__enter__ ` is loaded for later use .
403
403
404
404
#. The context manager's :meth: `__exit__ ` is loaded for later use.
405
405
406
+ #. The context manager's :meth: `__enter__ ` method is invoked.
407
+
406
408
#. If a target was included in the :keyword: `with ` statement, the return value
407
409
from :meth: `__enter__ ` is assigned to it.
408
410
@@ -438,9 +440,10 @@ The following code::
438
440
is semantically equivalent to::
439
441
440
442
manager = (expression)
441
- value = type(manager).__enter__(manager)
443
+ enter = type(manager).__enter__
442
444
exit = type(manager).__exit__
443
- target = value
445
+ value = enter(manager)
446
+ target = value # only if `as target` is present in the with statement
444
447
exception = False
445
448
446
449
try:
@@ -841,8 +844,9 @@ is semantically equivalent to::
841
844
842
845
manager = (expression)
843
846
aexit = type(manager).__aexit__
844
- value = type(manager).__aenter__(manager)
845
- target = await value
847
+ aenter = type(manager).__aenter__
848
+ value = await aenter(manager)
849
+ target = value # only if `as target` is present in the with statement
846
850
exception = False
847
851
848
852
try:
You can’t perform that action at this time.
0 commit comments