T-string below Python 3.14 also reports import-not-found for string.templatelib on line 1
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 74/100
Direzione di ricerca
Inizia da State.compute_dependencies in mypy/build.py, dove, secondo l’issue, viene aggiunto string.templatelib quando tree.uses_template_strings è impostato. Controlla come viene rappresentata nelle opzioni la versione di Python di destinazione e aggiungi un caso di regressione a mypy/test/testcheck.py per una t-string destinata a Python 3.13. Il lavoro è completato quando quel caso segnala solo l’errore di versione alla riga 2 e il comportamento dei template string di Python 3.14 continua a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 20.7k
- Fork
- 3.3k
- Merge medio
- 1g 20h
- PR unite (30g)
- 106
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/mypy
-
Regression in 2.4.0: empty constraint tuple in PEP 695 type parameter (`class C[T: ()]`) is no longer reportedForse già presa @CheerathAniketh l’ha presa 3 giorni fa. Apertatopic-parser topic-pep-695
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python/mypy#22176 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
`stubgen --inspect-mode` crashes with `AttributeError on PEP 604 union syntax (X | Y)` *(mypy 2.1.0)*Forse già presa @ayushdoesdev l’ha presa 70 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Inconsistent description of `strict_optional`Forse già presa @Joosboy l’ha presa 87 giorni fa. Apertadocumentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python/mypy#21658 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Cannot set `output` in `mypy.ini`Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
python/mypy#21376 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
onyx-dot-app/onyx#16016 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
black --check exits 0 and prints All done when a multi file run is interruptedForse già presa @jiteshgulati l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
Non-positive worker counts wait for results without starting workersForse già presa @IlyaKhalafi l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno