Search notes:

CPython: Include/symtable.h

struct symtable {
    PyObject *st_filename;          /* name of file being compiled, decoded from the filesystem encoding */
    struct _symtable_entry *st_cur; /* current symbol table entry */
    struct _symtable_entry *st_top; /* symbol table entry for module */
    PyObject *st_blocks;            /* dict: map AST node addresses  to symbol table entries */
    PyObject *st_stack;             /* list: stack of namespace info */
    PyObject *st_global;            /* borrowed ref to st_top->ste_symbols */
    int st_nblocks;                 /* number of blocks used. kept for consistency with the corresponding compiler structure */
    PyObject *st_private;           /* name of current class or NULL */
    PyFutureFeatures *st_future;    /* module's future features that affect the symbol table */
    int recursion_depth;            /* current recursion depth */
    int recursion_limit;            /* recursion limit */
};
typedef struct _symtable_entry {
    PyObject_HEAD
    PyObject *ste_id;                     /* int: key in ste_table->st_blocks */
    PyObject *ste_symbols;                /* dict: variable names to flags */
    PyObject *ste_name;                   /* string: name of current block */
    PyObject *ste_varnames;               /* list of function parameters */
    PyObject *ste_children;               /* list of child blocks */
    PyObject *ste_directives;             /* locations of global and nonlocal statements */
    _Py_block_ty ste_type;                /* module, class, or Python functions */
    int ste_nested;                       /* true if block is nested */
    unsigned ste_free : 1;                /* true if block has free variables */
    unsigned ste_child_free : 1;          /* true if a child block has free vars, including free refs to globals */
    unsigned ste_generator : 1;           /* true if namespace is a generator */
    unsigned ste_coroutine : 1;           /* true if namespace is a coroutine */
    unsigned ste_comprehension : 1;       /* true if namespace is a list comprehension */
    unsigned ste_varargs : 1;             /* true if block has varargs */
    unsigned ste_varkeywords : 1;         /* true if block has varkeywords */
    unsigned ste_returns_value : 1;       /* true if namespace uses return with an argument */
    unsigned ste_needs_class_closure : 1; /* for class scopes, true if a closure over __class__ should be created */
    unsigned ste_comp_iter_target : 1;    /* true if visiting comprehension target */
    int ste_comp_iter_expr;               /* non-zero if visiting a comprehension range expression */
    int ste_lineno;                       /* first line of block */
    int ste_col_offset;                   /* offset of first line of block */
    int ste_opt_lineno;                   /* lineno of last exec or import * */
    int ste_opt_col_offset;               /* offset of last exec or import * */
    struct symtable *ste_table;
} PySTEntryObject;

See also

symbol table

Links

Eli Bendersky: Python internals: Symbol tables, part 2

Index