File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -1043,11 +1043,20 @@ All of the following opcodes use their arguments.
1043
1043
1044
1044
.. opcode :: LOAD_FAST (var_num)
1045
1045
1046
- Pushes a reference to the local ``co_varnames[var_num] `` onto the stack.
1047
- Closures are also handled by this operation.
1046
+ Pushes a reference to a local variable or closure cell onto the stack.
1047
+ The corresponding variable name is
1048
+ ``(co_varnames + co_cellvars + co_freevars)[var_num] ``.
1049
+
1050
+ For closures, note that ``LOAD_FAST `` loads the cell object contained
1051
+ in the corresponding slot of the cell and free variable storage,
1052
+ at index ``var_num - len(co_varnames) ``.
1053
+ In contrast, ``LOAD_DEREF `` gets the object the cell references.
1054
+
1055
+ Use of ``LOAD_FAST `` for closures is primarily to share cells objects
1056
+ from an outer closure when creating an inner one with ``MAKE_FUNCTION ``.
1048
1057
1049
1058
.. versionchanged :: 3.10
1050
- Closures are handled here now instead of ``LOAD_CLOSURE `` (removed).
1059
+ Closure cells are handled here now instead of ``LOAD_CLOSURE `` (removed).
1051
1060
1052
1061
1053
1062
.. opcode :: STORE_FAST (var_num)
You can’t perform that action at this time.
0 commit comments