@@ -188,9 +188,9 @@ operation is being performed, so the intermediate analysis object isn't useful:
188
188
For a module, it disassembles all functions. For a class, it disassembles
189
189
all methods (including class and static methods). For a code object or
190
190
sequence of raw bytecode, it prints one line per bytecode instruction.
191
- It also recursively disassembles nested code objects (the code of
192
- comprehensions, generator expressions and nested functions, and the code
193
- used for building nested classes) .
191
+ It also recursively disassembles nested code objects. These can include
192
+ generator expressions, nested functions, the bodies of nested classes,
193
+ and the code objects used for :ref: ` annotation scopes < annotation-scopes >` .
194
194
Strings are first compiled to code objects with the :func: `compile `
195
195
built-in function before being disassembled. If no object is provided, this
196
196
function disassembles the last traceback.
@@ -926,6 +926,27 @@ iterations of the loop.
926
926
.. opcode :: LOAD_NAME (namei)
927
927
928
928
Pushes the value associated with ``co_names[namei] `` onto the stack.
929
+ The name is looked up within the locals, then the globals, then the builtins.
930
+
931
+
932
+ .. opcode :: LOAD_LOCALS
933
+
934
+ Pushes a reference to the locals dictionary onto the stack. This is used
935
+ to prepare namespace dictionaries for :opcode: `LOAD_FROM_DICT_OR_DEREF `
936
+ and :opcode: `LOAD_FROM_DICT_OR_GLOBALS `.
937
+
938
+ .. versionadded :: 3.12
939
+
940
+
941
+ .. opcode :: LOAD_FROM_DICT_OR_GLOBALS (i)
942
+
943
+ Pops a mapping off the stack and looks up the value for ``co_names[namei] ``.
944
+ If the name is not found there, looks it up in the globals and then the builtins,
945
+ similar to :opcode: `LOAD_GLOBAL `.
946
+ This is used for loading global variables in
947
+ :ref: `annotation scopes <annotation-scopes >` within class bodies.
948
+
949
+ .. versionadded :: 3.12
929
950
930
951
931
952
.. opcode :: BUILD_TUPLE (count)
@@ -1243,16 +1264,17 @@ iterations of the loop.
1243
1264
``i `` is no longer offset by the length of ``co_varnames ``.
1244
1265
1245
1266
1246
- .. opcode :: LOAD_CLASSDEREF (i)
1267
+ .. opcode :: LOAD_FROM_DICT_OR_DEREF (i)
1247
1268
1248
- Much like :opcode: `LOAD_DEREF ` but first checks the locals dictionary before
1249
- consulting the cell. This is used for loading free variables in class
1250
- bodies.
1251
-
1252
- .. versionadded :: 3.4
1269
+ Pops a mapping off the stack and looks up the name associated with
1270
+ slot ``i `` of the "fast locals" storage in this mapping.
1271
+ If the name is not found there, loads it from the cell contained in
1272
+ slot ``i ``, similar to :opcode: `LOAD_DEREF `. This is used for loading
1273
+ free variables in class bodies (which previously used
1274
+ :opcode: `!LOAD_CLASSDEREF `) and in
1275
+ :ref: `annotation scopes <annotation-scopes >` within class bodies.
1253
1276
1254
- .. versionchanged :: 3.11
1255
- ``i `` is no longer offset by the length of ``co_varnames ``.
1277
+ .. versionadded :: 3.12
1256
1278
1257
1279
1258
1280
.. opcode :: STORE_DEREF (i)
@@ -1504,13 +1526,45 @@ iterations of the loop.
1504
1526
1505
1527
The operand determines which intrinsic function is called:
1506
1528
1507
- * ``0 `` Not valid
1508
- * ``1 `` Prints the argument to standard out. Used in the REPL.
1509
- * ``2 `` Performs ``import * `` for the named module.
1510
- * ``3 `` Extracts the return value from a ``StopIteration `` exception.
1511
- * ``4 `` Wraps an aync generator value
1512
- * ``5 `` Performs the unary ``+ `` operation
1513
- * ``6 `` Converts a list to a tuple
1529
+ +-----------------------------------+-----------------------------------+
1530
+ | Operand | Description |
1531
+ +===================================+===================================+
1532
+ | ``INTRINSIC_1_INVALID `` | Not valid |
1533
+ +-----------------------------------+-----------------------------------+
1534
+ | ``INTRINSIC_PRINT `` | Prints the argument to standard |
1535
+ | | out. Used in the REPL. |
1536
+ +-----------------------------------+-----------------------------------+
1537
+ | ``INTRINSIC_IMPORT_STAR `` | Performs ``import * `` for the |
1538
+ | | named module. |
1539
+ +-----------------------------------+-----------------------------------+
1540
+ | ``INTRINSIC_STOPITERATION_ERROR `` | Extracts the return value from a |
1541
+ | | ``StopIteration `` exception. |
1542
+ +-----------------------------------+-----------------------------------+
1543
+ | ``INTRINSIC_ASYNC_GEN_WRAP `` | Wraps an aync generator value |
1544
+ +-----------------------------------+-----------------------------------+
1545
+ | ``INTRINSIC_UNARY_POSITIVE `` | Performs the unary ``+ `` |
1546
+ | | operation |
1547
+ +-----------------------------------+-----------------------------------+
1548
+ | ``INTRINSIC_LIST_TO_TUPLE `` | Converts a list to a tuple |
1549
+ +-----------------------------------+-----------------------------------+
1550
+ | ``INTRINSIC_TYPEVAR `` | Creates a :class: `typing.TypeVar ` |
1551
+ +-----------------------------------+-----------------------------------+
1552
+ | ``INTRINSIC_PARAMSPEC `` | Creates a |
1553
+ | | :class: `typing.ParamSpec ` |
1554
+ +-----------------------------------+-----------------------------------+
1555
+ | ``INTRINSIC_TYPEVARTUPLE `` | Creates a |
1556
+ | | :class: `typing.TypeVarTuple ` |
1557
+ +-----------------------------------+-----------------------------------+
1558
+ | ``INTRINSIC_SUBSCRIPT_GENERIC `` | Returns :class: `typing.Generic ` |
1559
+ | | subscripted with the argument |
1560
+ +-----------------------------------+-----------------------------------+
1561
+ | ``INTRINSIC_TYPEALIAS `` | Creates a |
1562
+ | | :class: `typing.TypeAliasType `; |
1563
+ | | used in the :keyword: `type ` |
1564
+ | | statement. The argument is a tuple|
1565
+ | | of the type alias's name, |
1566
+ | | type parameters, and value. |
1567
+ +-----------------------------------+-----------------------------------+
1514
1568
1515
1569
.. versionadded :: 3.12
1516
1570
@@ -1522,8 +1576,25 @@ iterations of the loop.
1522
1576
1523
1577
The operand determines which intrinsic function is called:
1524
1578
1525
- * ``0 `` Not valid
1526
- * ``1 `` Calculates the :exc: `ExceptionGroup ` to raise from a ``try-except* ``.
1579
+ +----------------------------------------+-----------------------------------+
1580
+ | Operand | Description |
1581
+ +========================================+===================================+
1582
+ | ``INTRINSIC_2_INVALID `` | Not valid |
1583
+ +----------------------------------------+-----------------------------------+
1584
+ | ``INTRINSIC_PREP_RERAISE_STAR `` | Calculates the |
1585
+ | | :exc: `ExceptionGroup ` to raise |
1586
+ | | from a ``try-except* ``. |
1587
+ +----------------------------------------+-----------------------------------+
1588
+ | ``INTRINSIC_TYPEVAR_WITH_BOUND `` | Creates a :class: `typing.TypeVar ` |
1589
+ | | with a bound. |
1590
+ +----------------------------------------+-----------------------------------+
1591
+ | ``INTRINSIC_TYPEVAR_WITH_CONSTRAINTS `` | Creates a |
1592
+ | | :class: `typing.TypeVar ` with |
1593
+ | | constraints. |
1594
+ +----------------------------------------+-----------------------------------+
1595
+ | ``INTRINSIC_SET_FUNCTION_TYPE_PARAMS `` | Sets the ``__type_params__ `` |
1596
+ | | attribute of a function. |
1597
+ +----------------------------------------+-----------------------------------+
1527
1598
1528
1599
.. versionadded :: 3.12
1529
1600
0 commit comments