Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen Anfängerfreundlich
#160,810 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@anistark arbeitet bereits daran.

Seit 29.10.2026.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
testing

Rechercherichtung

Lies Lib/symtable.py, insbesondere die Stellen, an denen _flags und _scopes_value_to_name aus globals() gebildet werden, und vergleiche diese Namen mit den Konstanten in _symtable. Führe zuerst das gemeldete repr()-Beispiel mit -X lazy_imports=all aus; führe dann test_symtable mit und ohne Lazy Imports aus. Das Ziel ist erreicht, wenn Symbole in beiden Modi ihre erwarteten Flags und Scope-Namen anzeigen und der Test nicht mehr aus Lib/test/lazy_imports_all_exclude.txt ausgeschlossen werden muss.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
Python
Sterne
77.8k
Forks
37.7k
Ø Merge
12 Std. 14 Min.
Gemergte PRs (30 T.)
729

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/cpython

Alle Issues in python/cpython

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.