Feature or enhancement
The symbol table analysis computes a number of per-scope attributes that the compiler relies on, but does not expose them. I propose to add them as read-only attributes of the symbol table entries: is_generator, is_coroutine, has_annotations, has_conditional_annotations, needs_class_closure, needs_classdict, can_see_class_scope and annotation_block.
>>> import _symtable
>>> top = _symtable.symtable("async def f(): yield", "<string>", "exec")
>>> f = next(c for c in top.children if c.name == "f")
>>> f.is_generator, f.is_coroutine
(True, True)
A consumer currently has to re-derive these by walking the AST and replicating the exact rules of Python/symtable.c, which can change between versions. Trivially derivable attributes (like whether a function has a *args parameter or a docstring) are left out, but can be added later.
Linked PRs
Feature or enhancement
The symbol table analysis computes a number of per-scope attributes that the compiler relies on, but does not expose them. I propose to add them as read-only attributes of the symbol table entries:
is_generator,is_coroutine,has_annotations,has_conditional_annotations,needs_class_closure,needs_classdict,can_see_class_scopeandannotation_block.A consumer currently has to re-derive these by walking the AST and replicating the exact rules of
Python/symtable.c, which can change between versions. Trivially derivable attributes (like whether a function has a*argsparameter or a docstring) are left out, but can be added later.Linked PRs