T-string below Python 3.14 also reports import-not-found for string.templatelib on line 1
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 74/100
Línea de trabajo
Empieza por State.compute_dependencies en mypy/build.py, donde, según el issue, se añade string.templatelib cuando tree.uses_template_strings está establecido. Comprueba cómo se representa la versión de Python de destino en las opciones y añade un caso de regresión a mypy/test/testcheck.py para un t-string cuyo destino sea Python 3.13. El trabajo estará terminado cuando ese caso solo informe del error de versión de la línea 2 y el comportamiento de los template strings de Python 3.14 siga funcionando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 20.7k
- Forks
- 3.3k
- Merge medio
- 1 d 20 h
- PR fusionados (30 d)
- 106
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/mypy
-
Regression in 2.4.0: empty constraint tuple in PEP 695 type parameter (`class C[T: ()]`) is no longer reportedPosiblemente ocupada @CheerathAniketh la tomó hace 3 días. Abiertotopic-parser topic-pep-695
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python/mypy#22176 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`stubgen --inspect-mode` crashes with `AttributeError on PEP 604 union syntax (X | Y)` *(mypy 2.1.0)*Posiblemente ocupada @ayushdoesdev la tomó hace 71 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Inconsistent description of `strict_optional`Posiblemente ocupada @Joosboy la tomó hace 87 días. Abiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python/mypy#21658 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Cannot set `output` in `mypy.ini`Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertobug topic-configuration topic-error-reporting
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
python/mypy#21376 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de python/mypy
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
onyx-dot-app/onyx#16016 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
black --check exits 0 and prints All done when a multi file run is interruptedPosiblemente ocupada @jiteshgulati la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días
-
Non-positive worker counts wait for results without starting workersPosiblemente ocupada @IlyaKhalafi la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día