File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -430,13 +430,36 @@ The execution of the :keyword:`with` statement with one "item" proceeds as follo
430
430
value from :meth: `__exit__ ` is ignored, and execution proceeds at the normal
431
431
location for the kind of exit that was taken.
432
432
433
+ The following code::
434
+
435
+ with expression as target:
436
+ suite
437
+
438
+ is semantically equivalent to::
439
+
440
+ manager = (expression)
441
+ value = type(manager).__enter__(manager)
442
+ exit = type(manager).__exit__
443
+ target = value
444
+ exception = False
445
+
446
+ try:
447
+ suite
448
+ except:
449
+ exception = True
450
+ if not exit(manager, *sys.exc_info()):
451
+ raise
452
+ finally:
453
+ if not exception:
454
+ exit(manager, None, None, None)
455
+
433
456
With more than one item, the context managers are processed as if multiple
434
457
:keyword: `with ` statements were nested::
435
458
436
459
with A() as a, B() as b:
437
460
suite
438
461
439
- is equivalent to ::
462
+ is semantically equivalent to::
440
463
441
464
with A() as a:
442
465
with B() as b:
You can’t perform that action at this time.
0 commit comments