Skip to content

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

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

anistark wants to merge 4 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

Comment thread Lib/test/test_symtable.py Resolved

@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

anistark and others added 2 commits November 15, 2026 18:39
`repr()` of a `symtable.Symbol` no longer raises `TypeError` when all imports are lazy

Refs python#149640
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@anistark
anistark force-pushed the gh-160810-symtable-lazy-imports branch from 26a5cc1 to 96ce042 Compare November 15, 2026 13:12
Comment thread Lib/test/test_symtable.py Outdated
self.assertEqual(repr(class_A.lookup('x')),
"<symbol 'x': LOCAL, DEF_LOCAL|DEF_FREE_CLASS>")

@support.requires_subprocess()

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.

I don't remember well but is this decorator needed or is assert_python_ok already checking it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yea now that I'm checking more, I see it's not needed... _assert_python already has @support.requires_subprocess()

Removing it. Thanks for the review

anistark and others added 2 commits November 16, 2026 00:19
@picnixz

picnixz commented Nov 16, 2026

Copy link
Copy Markdown
Member

No need to update your branch, we'll merge it when we will have time!

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