T-string below Python 3.14 also reports import-not-found for string.templatelib on line 1
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 74/100
Rechercherichtung
Beginne mit State.compute_dependencies in mypy/build.py, wo laut Issue string.templatelib hinzugefügt wird, wenn tree.uses_template_strings gesetzt ist. Prüfe, wie die Zielversion von Python in den Optionen dargestellt wird, und füge in mypy/test/testcheck.py einen Regressionstestfall für einen t-String mit Zielversion Python 3.13 hinzu. Als abgeschlossen gilt die Arbeit, wenn dieser Testfall nur den Versionsfehler in Zeile 2 meldet und das Verhalten von Template-Strings in Python 3.14 weiterhin funktioniert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Bug Report
With a target below 3.14, a t-string gets the expected syntax error and also an import-not-found for string.templatelib, reported on line 1 of the file. Nothing on line 1 imports anything, and a # type: ignore on the t-string line does not silence it.
To Reproduce
y = 10
print(t"hello {y}")
Expected Behavior
Only the version error on line 2. The old parser stops at line 2 with Invalid syntax, so this is new with the native parser.
Actual Behavior
$ mypy --no-incremental --python-version 3.13 t1.py # master at fe98edc, also 2.4.0 (compiled)
t1.py:1: error: Cannot find implementation or library stub for module named "string.templatelib" [import-not-found]
t1.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
t1.py:2: error: T-strings: requires Python 3.14 or newer (current target: Python 3.13) [syntax]
Found 2 errors in 1 file (checked 1 source file)
State.compute_dependencies adds string.templatelib whenever tree.uses_template_strings is set (mypy/build.py:3447, from #20900). typeshed lists that module as 3.14-, so below 3.14 the dependency can't resolve, and it has no import line, so the error lands on line 1. Gating it on the target version removes the extra error:
if self.tree.uses_template_strings and self.options.python_version >= (3, 14):
self.add_dependency("string.templatelib")
$ mypy --no-incremental --python-version 3.13 t1.py # with that change
t1.py:2: error: T-strings: requires Python 3.14 or newer (current target: Python 3.13) [syntax]
Found 1 error in 1 file (checked 1 source file)
$ mypy --no-incremental --python-version 3.14 t4.py # Template annotation plus reveal_type(t"{y}")
t4.py:4: note: Revealed type is "string.templatelib.Template"
Success: no issues found in 1 source file
$ pytest -q -n 4 mypy/test/testcheck.py # with that change
8302 passed, 27 skipped, 7 xfailed in 73.00s
# no existing case covers a t-string below 3.14
Your Environment
- Mypy version used: 2.4.0 (compiled), and master at fe98edc (not compiled)
- Mypy command-line flags:
--no-incremental --python-version 3.13(3.12 gives the same) - Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.13.15
@JukkaL I'd put the gate in compute_dependencies as above, because it is one line and does not depend on which parser built the tree. Happy to open the pull request with a check-python314.test case if you agree.
- Vorherrschende Sprache
- Python
- Sterne
- 20.7k
- Forks
- 3.3k
- Ø Merge
- 1 T. 23 Std.
- Gemergte PRs (30 T.)
- 105
Entwicklungsumgebung
- 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/mypy
-
Regression in 2.4.0: empty constraint tuple in PEP 695 type parameter (`class C[T: ()]`) is no longer reportedEvtl. wieder frei @CheerathAniketh hat das vor 8 Tagen übernommen, und es ist kein Pull Request offen. Offentopic-parser topic-pep-695
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
python/mypy#22176 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
`stubgen --inspect-mode` crashes with `AttributeError on PEP 604 union syntax (X | Y)` *(mypy 2.1.0)*Evtl. vergeben @ayushdoesdev hat das vor 75 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
Inconsistent description of `strict_optional`Evtl. vergeben @Joosboy hat das vor 92 Tagen übernommen. Offendocumentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
python/mypy#21658 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Cannot set `output` in `mypy.ini`Evtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offenbug topic-configuration topic-error-reporting
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
python/mypy#21376 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
google-ai-edge/litert-torch#1346 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
geneontology/gocam-py#272 ·
-
pushed_authorization_request sends list authorization_details as a Python reprEvtl. vergeben @RaphaelFakhri hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
auth0/auth0-python#903 ·
Maintainer antworten meist innerhalb von 1 Tag