Skip to content

Commit 13fe60d

Browse files
Add a note about "locals plus" and variable kinds.
1 parent 235e4aa commit 13fe60d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Include/internal/pycore_code.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ struct _PyOpcache {
2626
};
2727

2828

29+
/* "Locals plus" for a code object is the set of locals + cell vars +
30+
* free vars. This relates to variable names as well as offsets into
31+
* the "fast locals" storage array of execution frames. The compiler
32+
* builds the list of names, their offsets, and the corresponding
33+
* kind of local.
34+
*
35+
* Those kinds represent the source of the initial value and the
36+
* variable's scope (as related to closures). A "local" is an
37+
* argument or other variable defined in the current scope. A "free"
38+
* variable is one that is defined in an outer scope and comes from
39+
* the function's closure. A "cell" variable is a local that escapes
40+
* into an inner function as part of a closure, and thus must be
41+
* wrapped in a cell. Any "local" can also be a "cell", but the
42+
* "free" kind is mutually exclusive with both.
43+
*/
44+
2945
// We would use an enum if C let us specify the storage type.
3046
typedef unsigned char _PyLocalsPlusKind;
3147
/* Note that these all fit within _PyLocalsPlusKind, as do combinations. */

0 commit comments

Comments
 (0)