Skip to content

gh-153849: Expose scope attributes on symtable entries#153850

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:symtable-ste-attrs
Open

gh-153849: Expose scope attributes on symtable entries#153850
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:symtable-ste-attrs

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 17, 2026

Copy link
Copy Markdown
Member

The symbol table analysis computes a number of per-scope attributes that the compiler relies on, but did not expose them. Add read-only attributes to the low-level symbol table entries: is_generator, is_coroutine, has_annotations, has_conditional_annotations, needs_class_closure, needs_classdict, can_see_class_scope and annotation_block.

Attributes that are trivially derivable from the AST (such as whether a function has a *args parameter) are deliberately not included; they can be added later.

🤖 Generated with Claude Code

The symbol table analysis computes a number of per-scope attributes
that the compiler relies on, but did not expose them.  Add read-only
attributes to 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.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@carljm
carljm removed their request for review July 17, 2026 17:30

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exposing private implementation details of the compiler that we might want to change later. What would the backward compatibility implications be if we want to (for example) get rid of can_see_class_scope in a later version?

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

First of all, this attributes are added to a class in private module _symtable. It is not even documented. Public module symtable wraps it in other other class which does not expose these attributes.

Currently I am playing with Python implementation of the compiler. None of these attributes are essential, they can be derived from the AST, and the first version of the compiler did it. But they are not trivially derivable. Exposing them in _symtable makes the code simpler. These attributes are needed for the C compiler, we cannot simply get rid of them. If we can get rid of them, this implies serious semantic changes in Python language. If the C compiler no longer need them, then outer tools do not need them either.

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, if this stays limited to a private module I have no concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants