Skip to content

Commit ed29f52

Browse files
Various small fixes to dis docs (#103923)
- Fix description of MAKE_CELL, which appeared to be inverted from the actual behavior - Fix stray ".:" (sphinx-contrib/sphinx-lint#63) - Fix inconsistent indentation - Add some missing code blocks - Slight style improvements
1 parent 738c226 commit ed29f52

File tree

1 file changed

+79
-78
lines changed

1 file changed

+79
-78
lines changed

Doc/library/dis.rst

+79-78
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ The Python compiler currently generates the following bytecode instructions.
402402

403403
**General instructions**
404404

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
406406
operations on it as if it was a Python list. The top of the stack corresponds to
407407
``STACK[-1]`` in this language.
408408

@@ -414,15 +414,15 @@ operations on it as if it was a Python list. The top of the stack corresponds to
414414

415415
.. opcode:: POP_TOP
416416

417-
Removes the top-of-stack item.::
417+
Removes the top-of-stack item::
418418

419419
STACK.pop()
420420

421421

422422
.. opcode:: END_FOR
423423

424424
Removes the top two values from the stack.
425-
Equivalent to POP_TOP; POP_TOP.
425+
Equivalent to ``POP_TOP``; ``POP_TOP``.
426426
Used to clean up at the end of loops, hence the name.
427427

428428
.. versionadded:: 3.12
@@ -431,7 +431,7 @@ operations on it as if it was a Python list. The top of the stack corresponds to
431431
.. opcode:: COPY (i)
432432

433433
Push the i-th item to the top of the stack without removing it from its original
434-
location.::
434+
location::
435435

436436
assert i > 0
437437
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
441441

442442
.. opcode:: SWAP (i)
443443

444-
Swap the top of the stack with the i-th element.::
444+
Swap the top of the stack with the i-th element::
445445

446446
STACK[-i], STACK[-1] = stack[-1], STACK[-i]
447447

@@ -513,7 +513,7 @@ not have to be) the original ``STACK[-2]``.
513513
.. opcode:: BINARY_OP (op)
514514

515515
Implements the binary and in-place operators (depending on the value of
516-
*op*).::
516+
*op*)::
517517

518518
rhs = STACK.pop()
519519
lhs = STACK.pop()
@@ -580,14 +580,14 @@ not have to be) the original ``STACK[-2]``.
580580

581581
Implements ``STACK[-1] = get_awaitable(STACK[-1])``, where ``get_awaitable(o)``
582582
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
584584
``o.__await__``.
585585

586586
If the ``where`` operand is nonzero, it indicates where the instruction
587587
occurs:
588588

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__``
591591

592592
.. versionadded:: 3.5
593593

@@ -652,6 +652,7 @@ not have to be) the original ``STACK[-2]``.
652652
.. opcode:: SET_ADD (i)
653653

654654
Implements::
655+
655656
item = STACK.pop()
656657
set.add(STACK[-i], item)
657658

@@ -705,11 +706,11 @@ iterations of the loop.
705706

706707
Yields ``STACK.pop()`` from a :term:`generator`.
707708

708-
.. versionchanged:: 3.11
709-
oparg set to be the stack depth.
709+
.. versionchanged:: 3.11
710+
oparg set to be the stack depth.
710711

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.
713714

714715

715716
.. opcode:: SETUP_ANNOTATIONS
@@ -726,32 +727,32 @@ iterations of the loop.
726727

727728
Pops a value from the stack, which is used to restore the exception state.
728729

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.
731732

732733
.. opcode:: RERAISE
733734

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.
737738

738-
.. versionadded:: 3.9
739+
.. versionadded:: 3.9
739740

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.
742743

743744
.. opcode:: PUSH_EXC_INFO
744745

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.
748749

749-
.. versionadded:: 3.11
750+
.. versionadded:: 3.11
750751

751752
.. opcode:: CHECK_EXC_MATCH
752753

753754
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
755756
result of the test.
756757

757758
.. versionadded:: 3.11
@@ -770,16 +771,16 @@ iterations of the loop.
770771

771772
.. opcode:: WITH_EXCEPT_START
772773

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.
777778

778-
.. versionadded:: 3.9
779+
.. versionadded:: 3.9
779780

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.
783784

784785

785786
.. opcode:: LOAD_ASSERTION_ERROR
@@ -863,7 +864,7 @@ iterations of the loop.
863864
.. opcode:: UNPACK_SEQUENCE (count)
864865

865866
Unpacks ``STACK[-1]`` into *count* individual values, which are put onto the stack
866-
right-to-left.::
867+
right-to-left::
867868

868869
STACK.extend(STACK.pop()[:count:-1])
869870

@@ -1028,7 +1029,7 @@ iterations of the loop.
10281029
This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the
10291030
correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
10301031
``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
10321033
the attribute lookup are pushed.
10331034

10341035
.. versionchanged:: 3.12
@@ -1207,7 +1208,7 @@ iterations of the loop.
12071208

12081209
.. opcode:: MAKE_CELL (i)
12091210

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
12111212
that value is stored into the new cell.
12121213

12131214
.. versionadded:: 3.11
@@ -1332,9 +1333,9 @@ iterations of the loop.
13321333

13331334
.. opcode:: PUSH_NULL
13341335

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.
13381339

13391340
.. versionadded:: 3.11
13401341

@@ -1434,38 +1435,38 @@ iterations of the loop.
14341435

14351436
.. opcode:: RESUME (where)
14361437

1437-
A no-op. Performs internal tracing, debugging and optimization checks.
1438+
A no-op. Performs internal tracing, debugging and optimization checks.
14381439

1439-
The ``where`` operand marks where the ``RESUME`` occurs:
1440+
The ``where`` operand marks where the ``RESUME`` occurs:
14401441

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
14461447

14471448
.. versionadded:: 3.11
14481449

14491450

14501451
.. opcode:: RETURN_GENERATOR
14511452

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.
14551456

1456-
.. versionadded:: 3.11
1457+
.. versionadded:: 3.11
14571458

14581459

14591460
.. opcode:: SEND (delta)
14601461

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.
14631464

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*.
14671468

1468-
.. versionadded:: 3.11
1469+
.. versionadded:: 3.11
14691470

14701471

14711472
.. opcode:: HAVE_ARGUMENT
@@ -1493,15 +1494,15 @@ iterations of the loop.
14931494
argument and sets ``STACK[-1]`` to the result. Used to implement
14941495
functionality that is necessary but not performance critical.
14951496

1496-
The operand determines which intrinsic function is called:
1497+
The operand determines which intrinsic function is called:
14971498

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
15051506

15061507
.. versionadded:: 3.12
15071508

@@ -1511,17 +1512,17 @@ iterations of the loop.
15111512
arguments and sets ``STACK[-1]`` to the result. Used to implement functionality that is
15121513
necessary but not performance critical.
15131514

1514-
The operand determines which intrinsic function is called:
1515+
The operand determines which intrinsic function is called:
15151516

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*``.
15181519

15191520
.. versionadded:: 3.12
15201521

15211522

15221523
**Pseudo-instructions**
15231524

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
15251526
but are replaced by real opcodes or removed before bytecode is generated.
15261527

15271528
.. opcode:: SETUP_FINALLY (target)
@@ -1533,7 +1534,7 @@ but are replaced by real opcodes or removed before bytecode is generated.
15331534

15341535
.. opcode:: SETUP_CLEANUP (target)
15351536

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
15371538
instruction (``lasti``) to the stack so that ``RERAISE`` can restore it.
15381539
If an exception occurs, the value stack level and the last instruction on
15391540
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.
15421543

15431544
.. opcode:: SETUP_WITH (target)
15441545

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
15461547
from the stack before control is transferred to the exception handler at
15471548
``target``.
15481549

@@ -1576,9 +1577,9 @@ Opcode collections
15761577
These collections are provided for automatic introspection of bytecode
15771578
instructions:
15781579

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``.
15821583

15831584
.. data:: opname
15841585

@@ -1599,7 +1600,7 @@ instructions:
15991600

16001601
Sequence of bytecodes that use their argument.
16011602

1602-
.. versionadded:: 3.12
1603+
.. versionadded:: 3.12
16031604

16041605

16051606
.. data:: hasconst
@@ -1609,10 +1610,10 @@ instructions:
16091610

16101611
.. data:: hasfree
16111612

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
16131614
context refers to names in the current scope that are referenced by inner
16141615
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.
16161617

16171618

16181619
.. data:: hasname
@@ -1643,4 +1644,4 @@ instructions:
16431644

16441645
Sequence of bytecodes that set an exception handler.
16451646

1646-
.. versionadded:: 3.12
1647+
.. versionadded:: 3.12

0 commit comments

Comments
 (0)