Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#160,810 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@anistark is already working on this.

Since Oct 29, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
testing

Research direction

Read Lib/symtable.py, especially where _flags and _scopes_value_to_name are built from globals(), and compare those names with the constants in _symtable. Start by running the reported repr() example with -X lazy_imports=all; then run test_symtable with and without lazy imports. Done means symbols show their expected flags and scope names in both modes, and the test no longer needs exclusion from Lib/test/lazy_imports_all_exclude.txt.

Written by the indexing model from the issue text.

Description

stdlib topic-lazy-imports type-bug

Bug report

Bug description:

With -X lazy_imports=all, repr() of a symtable.Symbol raises TypeError:

import symtable
top = symtable.symtable('x = 1', '<string>', 'exec')
print(top.get_symbols())
$ ./python -X lazy_imports=all repro.py
Traceback (most recent call last):
  File "repro.py", line 3, in <module>
    print(top.get_symbols())
    ~~~~~^^^^^^^^^^^^^^^^^^^
  File "Lib/symtable.py", line 264, in __repr__
    flags_str = '|'.join(self._flags_str())
  File "Lib/symtable.py", line 272, in _flags_str
    if self.__flags & flagvalue == flagvalue:
       ~~~~~~~~~~~~~^~~~~~~~~~~
TypeError: unsupported operand type(s) for &: 'int' and 'lazy_import'

Without the option it prints [<symbol 'x': LOCAL, DEF_LOCAL>].

Lib/symtable.py builds its _flags and _scopes_value_to_name tables from globals(): https://github.com/python/cpython/blob/c79146a9eb05dea735a6a22dc004379cdec3ed0e/Lib/symtable.py#L388-L391

With lazy_imports=all, the from _symtable import ... at the top of the module is lazy, so globals() holds lazy_import objects instead of the integer constants. _flags breaks repr() as above, and once that is fixed, _scopes_value_to_name still makes the scope print as 1 instead of LOCAL.

This is the test_symtable failure mentioned in gh-149640, and why test_symtable is in Lib/test/lazy_imports_all_exclude.txt. The 3.15 branch has the same code.

Possible fix: take the values from the _symtable module (for example getattr(_symtable, name)) instead of from globals(). With that, test_symtable passes with and without -X lazy_imports=all and can come off the exclusion list. I can open a PR if this sounds right.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-160866
Dominant language
Python
Stars
77.8k
Forks
37.7k
Avg merge
11h 25m
Merged PRs (30d)
723

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.