symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
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
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
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/cpython
-
tests topic-profiling type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
python/cpython#160881 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
3.16 build pending type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
python/cpython#160829 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
dependencies infra topic-ensurepip
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
Maintainer antworten meist innerhalb von 1 Tag
-
tarfile: extractfile(member).read() of a sparse member is slow due to repeated bytes concatenationEvtl. vergeben @devdavidejesus hat das heute übernommen. Offenperformance stdlib triaged type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
python/cpython#160774 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
tests topic-profiling type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
python/cpython#160334 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Support .aac audio uploadsEvtl. vergeben @julien731 hat das heute übernommen. Offenfeature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
nimblehq/audio-transcriber#153 ·
-
help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
antonyrag/ragleap-core#1062 ·
-
needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
gke-labs/kube-agents#4321 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Git-Hospital/githealthcheck#61 ·
Maintainer antworten meist innerhalb von 1 Tag
-
changelog investigate
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
ramnes/notion-sdk-py#433 ·