Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#22,184 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@jw9829 đang làm issue này rồi.

Từ ngày 12/10/2026.

  • #22188 của @jw9829 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với State.compute_dependencies trong mypy/build.py, nơi issue cho biết string.templatelib được thêm vào khi tree.uses_template_strings được đặt. Kiểm tra cách phiên bản Python mục tiêu được biểu diễn trong các tùy chọn và thêm một trường hợp hồi quy vào mypy/test/testcheck.py cho t-string nhắm đến Python 3.13. Hoàn tất khi trường hợp đó chỉ báo lỗi phiên bản ở dòng 2, còn hành vi template string của Python 3.14 vẫn hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
20.7k
Fork
3.3k
Merge trung bình
1 ngày 20 giờ
Pull request đã merge (30 ngày)
106

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.