On this page
symtable.Symbol
Prev: symtable.Function | Up: symtable | Next: symtable.SymbolTable
Rel: symtable.Class, symtable.Function, symtable.SymbolTable, symtable.SymbolTableType
Ref: docs.python.org — symtable.Symbol
Tags: #public #python3 #stdlib #symtable
Import
import symtable
from symtable import Symbol
Signature & Overview
symtable.Symbol(name, flags, namespaces=None, *, module_scope=False)
symtable.Symbol class.
Methods & Attributes
Symbol.get_name(self)— Return a name of a symbol.Symbol.get_namespace(self)— Return the single namespace bound to this name.Symbol.get_namespaces(self)— Return a list of namespaces bound to this nameSymbol.is_annotated(self)— Return True if the symbol is annotated.Symbol.is_assigned(self)— Return True if a symbol is assigned to.Symbol.is_comp_cell(self)— Return True if the symbol is a cell in an inlined comprehension.Symbol.is_comp_iter(self)— Return True if the symbol is a comprehension iteration variable.Symbol.is_declared_global(self)— Return True if the symbol is declared global with a global statement.Symbol.is_free(self)— Return True if a referenced symbol is not assigned to.Symbol.is_free_class(self)— Return True if a class-scoped symbol is free from the perspective of a method.Symbol.is_global(self)— Return True if the symbol is global.Symbol.is_imported(self)— Return True if the symbol is created from an import statement.Symbol.is_local(self)— Return True if the symbol is local.Symbol.is_namespace(self)— Returns True if name binding introduces new namespace.Symbol.is_nonlocal(self)— Return True if the symbol is nonlocal.Symbol.is_parameter(self)— Return True if the symbol is a parameter.Symbol.is_referenced(self)— Return True if the symbol is used in its block.Symbol.is_type_parameter(self)— Return True if the symbol is a type parameter.
Usage
import symtable
tbl = symtable.symtable('def f(x): return x', '<m>', 'exec')
sym = tbl.get_children()[0].lookup('x')
assert isinstance(sym, symtable.Symbol) and sym.is_parameter()
Gotchas
- Query binding flags:
is_local(),is_global(),is_free(),is_imported(),is_assigned().
REPL Inspect
from symtable import Symbol
help(Symbol)
Linked from
Related notes
- tuts/python3/stdlib_module/symtable/Class Linked here; links to this page; shared tags: #stdlib, #symtable
- tuts/python3/stdlib_module/symtable/Function Linked here; links to this page; shared tags: #stdlib, #symtable
- tuts/python3/stdlib_module/symtable/SymbolTable Linked here; links to this page; shared tags: #stdlib, #symtable
- tuts/python3/stdlib_module/symtable/SymbolTableType Linked here; links to this page; shared tags: #stdlib, #symtable
- tuts/python3/stdlib_module/symtable/symtable Linked here; links to this page; shared tags: #stdlib, #symtable
- tuts/python3/stdlib_module/symtable links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib