From 1d0f834701691dbf3f3d81cee39e7467fe96a19c Mon Sep 17 00:00:00 2001 From: jw9829 <245427686+jw9829@users.noreply.github.com> Date: Mon, 12 Oct 2026 15:16:10 -0400 Subject: [PATCH] Fix t-string dependency for older targets --- mypy/build.py | 2 +- test-data/unit/check-python314.test | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mypy/build.py b/mypy/build.py index 09952f37aa280..78bd732793c22 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -3444,7 +3444,7 @@ def compute_dependencies(self) -> None: # Every module implicitly depends on builtins. if self.id != "builtins": self.add_dependency("builtins") - if self.tree.uses_template_strings: + if self.tree.uses_template_strings and self.options.python_version >= (3, 14): self.add_dependency("string.templatelib") self.check_blockers() # Can fail due to bogus relative imports diff --git a/test-data/unit/check-python314.test b/test-data/unit/check-python314.test index c6944013c1d83..e7e7e790acd3b 100644 --- a/test-data/unit/check-python314.test +++ b/test-data/unit/check-python314.test @@ -14,6 +14,10 @@ a = t"foobar" a = t"{'foobar'}" [builtins fixtures/f_string.pyi] +[case testTemplateStringBelowTargetDoesNotImportTemplatelib] +# flags: --python-version=3.13 --native-parser +t"hello {1}" # E: T-strings: requires Python 3.14 or newer (current target: Python 3.13) + [case testTemplateStringWithoutExplicitImport] reveal_type(t"implicit import works") # N: Revealed type is "string.templatelib.Template" [builtins fixtures/f_string.pyi]