symtable entries should expose the scope attributes computed by the analysis
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
- gh-153850
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing linked PR gh-153850, then read the scope analysis in Python/symtable.c, which the issue identifies as the source of these attributes. Verify that the requested values are exposed as read-only symbol-table entry attributes and that the linked PR covers the stated cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100