Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

T-string below Python 3.14 also reports import-not-found for string.templatelib on line 1

Ouverte Adaptée aux débutants
#22,184 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@jw9829 y travaille déjà.

Depuis le 12/10/2026.

  • #22188 par @jw9829 — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
74/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
backend

Piste de recherche

Commencez par State.compute_dependencies dans mypy/build.py, où, selon l’issue, string.templatelib est ajouté lorsque tree.uses_template_strings est défini. Vérifiez comment la version cible de Python est représentée dans les options et ajoutez un cas de régression dans mypy/test/testcheck.py pour un t-string ciblant Python 3.13. Le travail est terminé lorsque ce cas ne signale que l’erreur de version à la ligne 2 et que le comportement des template strings de Python 3.14 fonctionne toujours.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug topic-parser
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.

Langage dominant
Python
Étoiles
20.7k
Forks
3.3k
Merge moyen
2 j 1 h
PR mergées (30 j)
104

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python/mypy

Toutes les issues de python/mypy

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.