symtable - Interface to the compiler's internal symbol tables
| Use Case | Command | Description |
|---|---|---|
| Parse source code | symtable.symtable(code, filename, compile_type) | Return top-level SymbolTable for the code |
| Get all symbols | table.get_symbols() | List of Symbol instances in the table |
| Lookup a name | table.lookup('name') | Return Symbol for the given name |
| Check symbol scope | sym.is_global() | Return True if the symbol is global |
| Get table type | table.get_type() | Returns 'class', 'module', or 'function' |
| Get class methods | class_table.get_methods() | Tuple of method names declared in the class |
| Get function locals | func_table.get_locals() | Tuple of local variable names |
| Get function globals | func_table.get_globals() | Tuple of global variable names |
| Get nested tables | table.get_children() | List of child symbol tables |
https://docs.python.org/3.10/library/symtable.html
The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.
Class(raw_table, filename)
Method resolution order:
get_methods(self) — Return a tuple of methods declared in the class.__init__(self, raw_table, filename) — Initialize self. See help(type(self)) for accurate signature.__repr__(self) — Return repr(self).get_children(self) — Return a list of the nested symbol tables.get_id(self) — Return an identifier for the table.get_identifiers(self) — Return a view object containing the names of symbols in the table.get_lineno(self) — Return the number of the first line in the block for the table.get_name(self) — Return the table's name. This corresponds to the name of the class, function or 'top' if the table is for a class, function or global respectively.get_symbols(self) — Return a list of Symbol instances for names in the table.get_type(self) — Return the type of the symbol table. The values returned are 'class', 'module' and 'function'.has_children(self) — Return True if the block has nested namespaces.is_nested(self) — Return True if the block is a nested class or function.is_optimized(self) — Return True if the locals in the table are optimizable.lookup(self, name) — Lookup a name in the table. Returns a Symbol instance.__dict__ — dictionary for instance variables (if defined)__weakref__ — list of weak references to the object (if defined)Function(raw_table, filename)
Method resolution order:
get_frees(self) — Return a tuple of free variables in the function.get_globals(self) — Return a tuple of globals in the function.get_locals(self) — Return a tuple of locals in the function.get_nonlocals(self) — Return a tuple of nonlocals in the function.get_parameters(self) — Return a tuple of parameters to the function.__init__(self, raw_table, filename) — Initialize self. See help(type(self)) for accurate signature.__repr__(self) — Return repr(self).get_children(self) — Return a list of the nested symbol tables.get_id(self) — Return an identifier for the table.get_identifiers(self) — Return a view object containing the names of symbols in the table.get_lineno(self) — Return the number of the first line in the block for the table.get_name(self) — Return the table's name. This corresponds to the name of the class, function or 'top' if the table is for a class, function or global respectively.get_symbols(self) — Return a list of Symbol instances for names in the table.get_type(self) — Return the type of the symbol table. The values returned are 'class', 'module' and 'function'.has_children(self) — Return True if the block has nested namespaces.is_nested(self) — Return True if the block is a nested class or function.is_optimized(self) — Return True if the locals in the table are optimizable.lookup(self, name) — Lookup a name in the table. Returns a Symbol instance.__dict__ — dictionary for instance variables (if defined)__weakref__ — list of weak references to the object (if defined)Symbol(name, flags, namespaces=None, *, module_scope=False)
__init__(self, name, flags, namespaces=None, *, module_scope=False) — Initialize self. See help(type(self)) for accurate signature.__repr__(self) — Return repr(self).get_name(self) — Return a name of a symbol.get_namespace(self) — Return the single namespace bound to this name. Raises ValueError if the name is bound to multiple namespaces.get_namespaces(self) — Return a list of namespaces bound to this name.is_annotated(self) — Return True if the symbol is annotated.is_assigned(self) — Return True if a symbol is assigned to.is_declared_global(self) — Return True if the symbol is declared global with a global statement.is_free(self) — Return True if a referenced symbol is not assigned to.is_global(self) — Return True if the symbol is global.is_imported(self) — Return True if the symbol is created from an import statement.is_local(self) — Return True if the symbol is local.is_namespace(self) — Returns True if name binding introduces new namespace. If the name is used as the target of a function or class statement, this will be true. Note that a single name can be bound to multiple objects. If is_namespace() is true, the name may also be bound to other objects, like an int or list, that does not introduce a new namespace.is_nonlocal(self) — Return True if the symbol is nonlocal.is_parameter(self) — Return True if the symbol is a parameter.is_referenced(self) — Return True if the symbol is used in its block.__dict__ — dictionary for instance variables (if defined)__weakref__ — list of weak references to the object (if defined)SymbolTable(raw_table, filename)
__init__(self, raw_table, filename) — Initialize self. See help(type(self)) for accurate signature.__repr__(self) — Return repr(self).get_children(self) — Return a list of the nested symbol tables.get_id(self) — Return an identifier for the table.get_identifiers(self) — Return a view object containing the names of symbols in the table.get_lineno(self) — Return the number of the first line in the block for the table.get_name(self) — Return the table's name. This corresponds to the name of the class, function or 'top' if the table is for a class, function or global respectively.get_symbols(self) — Return a list of Symbol instances for names in the table.get_type(self) — Return the type of the symbol table. The values returned are 'class', 'module' and 'function'.has_children(self) — Return True if the block has nested namespaces.is_nested(self) — Return True if the block is a nested class or function.is_optimized(self) — Return True if the locals in the table are optimizable.lookup(self, name) — Lookup a name in the table. Returns a Symbol instance.__dict__ — dictionary for instance variables (if defined)__weakref__ — list of weak references to the object (if defined)symtable(code, filename, compile_type) — Return the toplevel SymbolTable for the source code. filename is the name of the file with the code and compile_type is the compile() mode argument.__all__ = ['symtable', 'SymbolTable', 'Class', 'Function', 'Symbol']
/usr/lib/python3.10/symtable.py
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 13:15 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format