Skip to content

Commit 41b99c1

Browse files
authored
Add review suggestions
1 parent 28f27a4 commit 41b99c1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,13 @@ The execution of the :keyword:`with` statement with one "item" proceeds as follo
398398

399399
#. The context expression (the expression given in the :token:`with_item`) is
400400
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.
403403

404404
#. The context manager's :meth:`__exit__` is loaded for later use.
405405

406+
#. The context manager's :meth:`__enter__` method is invoked.
407+
406408
#. If a target was included in the :keyword:`with` statement, the return value
407409
from :meth:`__enter__` is assigned to it.
408410

@@ -438,9 +440,10 @@ The following code::
438440
is semantically equivalent to::
439441

440442
manager = (expression)
441-
value = type(manager).__enter__(manager)
443+
enter = type(manager).__enter__
442444
exit = type(manager).__exit__
443-
target = value
445+
value = enter(manager)
446+
target = value # only if `as target` is present in the with statement
444447
exception = False
445448

446449
try:
@@ -841,8 +844,9 @@ is semantically equivalent to::
841844

842845
manager = (expression)
843846
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
846850
exception = False
847851

848852
try:

0 commit comments

Comments
 (0)