@@ -402,7 +402,7 @@ The Python compiler currently generates the following bytecode instructions.
402
402
403
403
**General instructions **
404
404
405
- In the following, We will refer to the interpreter stack as STACK and describe
405
+ In the following, We will refer to the interpreter stack as `` STACK `` and describe
406
406
operations on it as if it was a Python list. The top of the stack corresponds to
407
407
``STACK[-1] `` in this language.
408
408
@@ -414,15 +414,15 @@ operations on it as if it was a Python list. The top of the stack corresponds to
414
414
415
415
.. opcode :: POP_TOP
416
416
417
- Removes the top-of-stack item. ::
417
+ Removes the top-of-stack item::
418
418
419
419
STACK.pop()
420
420
421
421
422
422
.. opcode :: END_FOR
423
423
424
424
Removes the top two values from the stack.
425
- Equivalent to POP_TOP; POP_TOP.
425
+ Equivalent to `` POP_TOP ``; `` POP_TOP `` .
426
426
Used to clean up at the end of loops, hence the name.
427
427
428
428
.. versionadded :: 3.12
@@ -431,7 +431,7 @@ operations on it as if it was a Python list. The top of the stack corresponds to
431
431
.. opcode :: COPY (i)
432
432
433
433
Push the i-th item to the top of the stack without removing it from its original
434
- location. ::
434
+ location::
435
435
436
436
assert i > 0
437
437
STACK.append(STACK[-i])
@@ -441,7 +441,7 @@ operations on it as if it was a Python list. The top of the stack corresponds to
441
441
442
442
.. opcode :: SWAP (i)
443
443
444
- Swap the top of the stack with the i-th element. ::
444
+ Swap the top of the stack with the i-th element::
445
445
446
446
STACK[-i], STACK[-1] = stack[-1], STACK[-i]
447
447
@@ -513,7 +513,7 @@ not have to be) the original ``STACK[-2]``.
513
513
.. opcode :: BINARY_OP (op)
514
514
515
515
Implements the binary and in-place operators (depending on the value of
516
- *op *). ::
516
+ *op *)::
517
517
518
518
rhs = STACK.pop()
519
519
lhs = STACK.pop()
@@ -580,14 +580,14 @@ not have to be) the original ``STACK[-2]``.
580
580
581
581
Implements ``STACK[-1] = get_awaitable(STACK[-1]) ``, where ``get_awaitable(o) ``
582
582
returns ``o `` if ``o `` is a coroutine object or a generator object with
583
- the CO_ITERABLE_COROUTINE flag, or resolves
583
+ the :data: ` ~inspect. CO_ITERABLE_COROUTINE` flag, or resolves
584
584
``o.__await__ ``.
585
585
586
586
If the ``where `` operand is nonzero, it indicates where the instruction
587
587
occurs:
588
588
589
- * ``1 `` After a call to ``__aenter__ ``
590
- * ``2 `` After a call to ``__aexit__ ``
589
+ * ``1 ``: After a call to ``__aenter__ ``
590
+ * ``2 ``: After a call to ``__aexit__ ``
591
591
592
592
.. versionadded :: 3.5
593
593
@@ -652,6 +652,7 @@ not have to be) the original ``STACK[-2]``.
652
652
.. opcode :: SET_ADD (i)
653
653
654
654
Implements::
655
+
655
656
item = STACK.pop()
656
657
set.add(STACK[-i], item)
657
658
@@ -705,11 +706,11 @@ iterations of the loop.
705
706
706
707
Yields ``STACK.pop() `` from a :term: `generator `.
707
708
708
- .. versionchanged :: 3.11
709
- oparg set to be the stack depth.
709
+ .. versionchanged :: 3.11
710
+ oparg set to be the stack depth.
710
711
711
- .. versionchanged :: 3.12
712
- oparg set to be the exception block depth, for efficient closing of generators.
712
+ .. versionchanged :: 3.12
713
+ oparg set to be the exception block depth, for efficient closing of generators.
713
714
714
715
715
716
.. opcode :: SETUP_ANNOTATIONS
@@ -726,32 +727,32 @@ iterations of the loop.
726
727
727
728
Pops a value from the stack, which is used to restore the exception state.
728
729
729
- .. versionchanged :: 3.11
730
- Exception representation on the stack now consist of one, not three, items.
730
+ .. versionchanged :: 3.11
731
+ Exception representation on the stack now consist of one, not three, items.
731
732
732
733
.. opcode :: RERAISE
733
734
734
- Re-raises the exception currently on top of the stack. If oparg is non-zero,
735
- pops an additional value from the stack which is used to set ``f_lasti ``
736
- of the current frame.
735
+ Re-raises the exception currently on top of the stack. If oparg is non-zero,
736
+ pops an additional value from the stack which is used to set ``f_lasti ``
737
+ of the current frame.
737
738
738
- .. versionadded :: 3.9
739
+ .. versionadded :: 3.9
739
740
740
- .. versionchanged :: 3.11
741
- Exception representation on the stack now consist of one, not three, items.
741
+ .. versionchanged :: 3.11
742
+ Exception representation on the stack now consist of one, not three, items.
742
743
743
744
.. opcode :: PUSH_EXC_INFO
744
745
745
- Pops a value from the stack. Pushes the current exception to the top of the stack.
746
- Pushes the value originally popped back to the stack.
747
- Used in exception handlers.
746
+ Pops a value from the stack. Pushes the current exception to the top of the stack.
747
+ Pushes the value originally popped back to the stack.
748
+ Used in exception handlers.
748
749
749
- .. versionadded :: 3.11
750
+ .. versionadded :: 3.11
750
751
751
752
.. opcode :: CHECK_EXC_MATCH
752
753
753
754
Performs exception matching for ``except ``. Tests whether the ``STACK[-2] ``
754
- is an exception matching ``STACK[-1] ``. Pops STACK[-1] and pushes the boolean
755
+ is an exception matching ``STACK[-1] ``. Pops `` STACK[-1] `` and pushes the boolean
755
756
result of the test.
756
757
757
758
.. versionadded :: 3.11
@@ -770,16 +771,16 @@ iterations of the loop.
770
771
771
772
.. opcode :: WITH_EXCEPT_START
772
773
773
- Calls the function in position 4 on the stack with arguments (type, val, tb)
774
- representing the exception at the top of the stack.
775
- Used to implement the call ``context_manager.__exit__(*exc_info()) `` when an exception
776
- has occurred in a :keyword: `with ` statement.
774
+ Calls the function in position 4 on the stack with arguments (type, val, tb)
775
+ representing the exception at the top of the stack.
776
+ Used to implement the call ``context_manager.__exit__(*exc_info()) `` when an exception
777
+ has occurred in a :keyword: `with ` statement.
777
778
778
- .. versionadded :: 3.9
779
+ .. versionadded :: 3.9
779
780
780
- .. versionchanged :: 3.11
781
- The ``__exit__ `` function is in position 4 of the stack rather than 7.
782
- Exception representation on the stack now consist of one, not three, items.
781
+ .. versionchanged :: 3.11
782
+ The ``__exit__ `` function is in position 4 of the stack rather than 7.
783
+ Exception representation on the stack now consist of one, not three, items.
783
784
784
785
785
786
.. opcode :: LOAD_ASSERTION_ERROR
@@ -863,7 +864,7 @@ iterations of the loop.
863
864
.. opcode :: UNPACK_SEQUENCE (count)
864
865
865
866
Unpacks ``STACK[-1] `` into *count * individual values, which are put onto the stack
866
- right-to-left. ::
867
+ right-to-left::
867
868
868
869
STACK.extend(STACK.pop()[:count:-1])
869
870
@@ -1028,7 +1029,7 @@ iterations of the loop.
1028
1029
This bytecode distinguishes two cases: if ``STACK[-1] `` has a method with the
1029
1030
correct name, the bytecode pushes the unbound method and ``STACK[-1] ``.
1030
1031
``STACK[-1] `` will be used as the first argument (``self ``) by :opcode: `CALL `
1031
- when calling the unbound method. Otherwise, ``NULL `` and the object return by
1032
+ when calling the unbound method. Otherwise, ``NULL `` and the object returned by
1032
1033
the attribute lookup are pushed.
1033
1034
1034
1035
.. versionchanged :: 3.12
@@ -1207,7 +1208,7 @@ iterations of the loop.
1207
1208
1208
1209
.. opcode :: MAKE_CELL (i)
1209
1210
1210
- Creates a new cell in slot ``i ``. If that slot is empty then
1211
+ Creates a new cell in slot ``i ``. If that slot is nonempty then
1211
1212
that value is stored into the new cell.
1212
1213
1213
1214
.. versionadded :: 3.11
@@ -1332,9 +1333,9 @@ iterations of the loop.
1332
1333
1333
1334
.. opcode :: PUSH_NULL
1334
1335
1335
- Pushes a ``NULL `` to the stack.
1336
- Used in the call sequence to match the ``NULL `` pushed by
1337
- :opcode: `LOAD_METHOD ` for non-method calls.
1336
+ Pushes a ``NULL `` to the stack.
1337
+ Used in the call sequence to match the ``NULL `` pushed by
1338
+ :opcode: `LOAD_METHOD ` for non-method calls.
1338
1339
1339
1340
.. versionadded :: 3.11
1340
1341
@@ -1434,38 +1435,38 @@ iterations of the loop.
1434
1435
1435
1436
.. opcode :: RESUME (where)
1436
1437
1437
- A no-op. Performs internal tracing, debugging and optimization checks.
1438
+ A no-op. Performs internal tracing, debugging and optimization checks.
1438
1439
1439
- The ``where `` operand marks where the ``RESUME `` occurs:
1440
+ The ``where `` operand marks where the ``RESUME `` occurs:
1440
1441
1441
- * ``0 `` The start of a function, which is neither a generator, coroutine
1442
- nor an async generator
1443
- * ``1 `` After a ``yield `` expression
1444
- * ``2 `` After a ``yield from `` expression
1445
- * ``3 `` After an ``await `` expression
1442
+ * ``0 `` The start of a function, which is neither a generator, coroutine
1443
+ nor an async generator
1444
+ * ``1 `` After a ``yield `` expression
1445
+ * ``2 `` After a ``yield from `` expression
1446
+ * ``3 `` After an ``await `` expression
1446
1447
1447
1448
.. versionadded :: 3.11
1448
1449
1449
1450
1450
1451
.. opcode :: RETURN_GENERATOR
1451
1452
1452
- Create a generator, coroutine, or async generator from the current frame.
1453
- Used as first opcode of in code object for the above mentioned callables.
1454
- Clear the current frame and return the newly created generator.
1453
+ Create a generator, coroutine, or async generator from the current frame.
1454
+ Used as first opcode of in code object for the above mentioned callables.
1455
+ Clear the current frame and return the newly created generator.
1455
1456
1456
- .. versionadded :: 3.11
1457
+ .. versionadded :: 3.11
1457
1458
1458
1459
1459
1460
.. opcode :: SEND (delta)
1460
1461
1461
- Equivalent to ``STACK[-1] = STACK[-2].send(STACK[-1]) ``. Used in ``yield from ``
1462
- and ``await `` statements.
1462
+ Equivalent to ``STACK[-1] = STACK[-2].send(STACK[-1]) ``. Used in ``yield from ``
1463
+ and ``await `` statements.
1463
1464
1464
- If the call raises :exc: `StopIteration `, pop both items, push the
1465
- exception's ``value `` attribute, and increment the bytecode counter by
1466
- *delta *.
1465
+ If the call raises :exc: `StopIteration `, pop both items, push the
1466
+ exception's ``value `` attribute, and increment the bytecode counter by
1467
+ *delta *.
1467
1468
1468
- .. versionadded :: 3.11
1469
+ .. versionadded :: 3.11
1469
1470
1470
1471
1471
1472
.. opcode :: HAVE_ARGUMENT
@@ -1493,15 +1494,15 @@ iterations of the loop.
1493
1494
argument and sets ``STACK[-1] `` to the result. Used to implement
1494
1495
functionality that is necessary but not performance critical.
1495
1496
1496
- The operand determines which intrinsic function is called:
1497
+ The operand determines which intrinsic function is called:
1497
1498
1498
- * ``0 `` Not valid
1499
- * ``1 `` Prints the argument to standard out. Used in the REPL.
1500
- * ``2 `` Performs ``import * `` for the named module.
1501
- * ``3 `` Extracts the return value from a ``StopIteration `` exception.
1502
- * ``4 `` Wraps an aync generator value
1503
- * ``5 `` Performs the unary ``+ `` operation
1504
- * ``6 `` Converts a list to a tuple
1499
+ * ``0 `` Not valid
1500
+ * ``1 `` Prints the argument to standard out. Used in the REPL.
1501
+ * ``2 `` Performs ``import * `` for the named module.
1502
+ * ``3 `` Extracts the return value from a ``StopIteration `` exception.
1503
+ * ``4 `` Wraps an aync generator value
1504
+ * ``5 `` Performs the unary ``+ `` operation
1505
+ * ``6 `` Converts a list to a tuple
1505
1506
1506
1507
.. versionadded :: 3.12
1507
1508
@@ -1511,17 +1512,17 @@ iterations of the loop.
1511
1512
arguments and sets ``STACK[-1] `` to the result. Used to implement functionality that is
1512
1513
necessary but not performance critical.
1513
1514
1514
- The operand determines which intrinsic function is called:
1515
+ The operand determines which intrinsic function is called:
1515
1516
1516
- * ``0 `` Not valid
1517
- * ``1 `` Calculates the :exc: `ExceptionGroup ` to raise from a ``try-except* ``.
1517
+ * ``0 `` Not valid
1518
+ * ``1 `` Calculates the :exc: `ExceptionGroup ` to raise from a ``try-except* ``.
1518
1519
1519
1520
.. versionadded :: 3.12
1520
1521
1521
1522
1522
1523
**Pseudo-instructions **
1523
1524
1524
- These opcodes do not appear in python bytecode, they are used by the compiler
1525
+ These opcodes do not appear in Python bytecode. They are used by the compiler
1525
1526
but are replaced by real opcodes or removed before bytecode is generated.
1526
1527
1527
1528
.. opcode :: SETUP_FINALLY (target)
@@ -1533,7 +1534,7 @@ but are replaced by real opcodes or removed before bytecode is generated.
1533
1534
1534
1535
.. opcode :: SETUP_CLEANUP (target)
1535
1536
1536
- Like ``SETUP_FINALLY ``, but in case of exception also pushes the last
1537
+ Like ``SETUP_FINALLY ``, but in case of an exception also pushes the last
1537
1538
instruction (``lasti ``) to the stack so that ``RERAISE `` can restore it.
1538
1539
If an exception occurs, the value stack level and the last instruction on
1539
1540
the frame are restored to their current state, and control is transferred
@@ -1542,7 +1543,7 @@ but are replaced by real opcodes or removed before bytecode is generated.
1542
1543
1543
1544
.. opcode :: SETUP_WITH (target)
1544
1545
1545
- Like ``SETUP_CLEANUP ``, but in case of exception one more item is popped
1546
+ Like ``SETUP_CLEANUP ``, but in case of an exception one more item is popped
1546
1547
from the stack before control is transferred to the exception handler at
1547
1548
``target ``.
1548
1549
@@ -1576,9 +1577,9 @@ Opcode collections
1576
1577
These collections are provided for automatic introspection of bytecode
1577
1578
instructions:
1578
1579
1579
- .. versionchanged :: 3.12
1580
- The collections now contain pseudo instructions as well. These are
1581
- opcodes with values ``>= MIN_PSEUDO_OPCODE ``.
1580
+ .. versionchanged :: 3.12
1581
+ The collections now contain pseudo instructions as well. These are
1582
+ opcodes with values ``>= MIN_PSEUDO_OPCODE ``.
1582
1583
1583
1584
.. data :: opname
1584
1585
@@ -1599,7 +1600,7 @@ instructions:
1599
1600
1600
1601
Sequence of bytecodes that use their argument.
1601
1602
1602
- .. versionadded :: 3.12
1603
+ .. versionadded :: 3.12
1603
1604
1604
1605
1605
1606
.. data :: hasconst
@@ -1609,10 +1610,10 @@ instructions:
1609
1610
1610
1611
.. data :: hasfree
1611
1612
1612
- Sequence of bytecodes that access a free variable (note that 'free' in this
1613
+ Sequence of bytecodes that access a free variable. 'free' in this
1613
1614
context refers to names in the current scope that are referenced by inner
1614
1615
scopes or names in outer scopes that are referenced from this scope. It does
1615
- *not * include references to global or builtin scopes) .
1616
+ *not * include references to global or builtin scopes.
1616
1617
1617
1618
1618
1619
.. data :: hasname
@@ -1643,4 +1644,4 @@ instructions:
1643
1644
1644
1645
Sequence of bytecodes that set an exception handler.
1645
1646
1646
- .. versionadded :: 3.12
1647
+ .. versionadded :: 3.12
0 commit comments