You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
symtable.symtable() should accept an AST object, like compile() #153844
symtable.symtable() currently only accepts str or bytes source. I propose to also accept an AST object, with the same semantics as the builtin compile(): the compile_type argument selects the expected root node, and future statements found in the tree are honored.
>>> import ast, symtable
>>> tree = ast.parse("def f(): pass")
>>> symtable.symtable(tree, "<string>", "exec")
<SymbolTable for top in <string>>
The restriction is an artifact of the module wrapper: the C implementation builds the symbol table from an AST anyway, and compile() has accepted AST input since Python 2.6. But there is no way to get scope information for a tree you already have — a transformed or synthesized AST has no source, and the only workaround is ast.unparse() plus re-parsing.
Activity
gh-153844: Support AST input in symtable.symtable() (GH-153845)