Skip to content

gh-160810: Fix symtable.Symbol repr under -X lazy_imports=all - #160866

Open
anistark wants to merge 2 commits into
python:mainfrom
anistark:gh-160810-symtable-lazy-imports
Open

anistark wants to merge 2 commits into
python:mainfrom
anistark:gh-160810-symtable-lazy-imports

Conversation

@anistark

@anistark anistark commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

repr() of a symtable.Symbol raised TypeError under -X lazy_imports=all. _flags and _scopes_value_to_name were built from globals(), which holds unresolved lazy import objects for the names imported from _symtable.

  • Build both tables from _symtable instead. The names and order are the same, so repr() output without lazy imports is unchanged
  • Remove test_symtable from Lib/test/lazy_imports_all_exclude.txt, so the lazy imports CI job now runs it
  • Add test_symbol_repr_lazy_imports, which checks repr() in a subprocess with -X lazy_imports=all

Testing: test_symtable passes normally and with -X lazy_imports=all (also with --fast-ci). The new test fails without the fix.

Fixes #160810

`repr()` of a `symtable.Symbol` no longer raises `TypeError` when all imports are lazy

Refs python#149640
Comment thread Lib/test/test_symtable.py

@picnixz picnixz 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.

Just a small nitpick for xref purposes

Co-authored-by: Bénédikt Tran <[email protected]>
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.

symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all

2 participants