symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
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
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
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from python/cpython
-
Null dereferencing of a pointer in initconfig.cPossibly taken @lazerg claimed this 1 day ago. Openinterpreter-core topic-C-API type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python/cpython#160962 · 4 comments ·
Maintainers usually reply within 1 day
-
tests topic-profiling type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
python/cpython#160881 · 1 comment ·
Maintainers usually reply within 1 day
-
3.16 build pending type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
python/cpython#160829 · 5 comments ·
Maintainers usually reply within 1 day
-
dependencies infra topic-ensurepip
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
tarfile: extractfile(member).read() of a sparse member is slow due to repeated bytes concatenationPossibly taken @devdavidejesus claimed this 2 days ago. Openperformance stdlib triaged type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
python/cpython#160774 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
namespace operations
Difficulty 1/5 Under an hour Newbie friendliness 65/100
EclipseFdn/open-vsx.org#15057 ·
Maintainers usually reply within 1 day
-
Mission statement: why this is free, in the README, Why This Exists and the wiki HomePossibly taken @ChiefGyk3D claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ChiefGyk3D/Clouds-Against-Humanity#348 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
vllm-project/vime#508 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day