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

Regression in 2.4.0: empty constraint tuple in PEP 695 type parameter (`class C[T: ()]`) is no longer reported

Đang mở Phù hợp với người mới
#22,176 1 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

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

Từ ngày 11/10/2026.

Đá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
72/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, testing-qa

Hướng nghiên cứu

Bắt đầu với bài kiểm tra tính phù hợp generics_syntax_declarations.py ở dòng 60, vốn đã mong đợi lỗi đối với class ClassK[T: ()]. So sánh kết quả giữa mypy 2.3.0 và 2.4.0, sau đó lần theo cách xử lý các ràng buộc rỗng cho tham số kiểu PEP 695. Hoàn thành khi bài kiểm tra báo lỗi “at least two constrained types” như mong đợi trong 2.4.0.

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

Mô tả

topic-parser topic-pep-695

Bug Report

mypy 2.4.0 no longer reports an error for a PEP 695 type parameter whose constraint tuple is empty (class C[T: ()]). mypy 2.1.0, 2.2.0 and 2.3.0 all report Type variable must have at least two constrained types [misc] on that line. The one-element case T: (str,) and the legacy TypeVar("T", str) are still reported in 2.4.0, so only the empty-tuple path regressed.

To Reproduce

class ClassK[T: ()]:  # expected: error: Type variable must have at least two constrained types  [misc]
    ...

class ClassL[T: (str,)]:  # still reported in 2.4.0
    ...
$ mypy --python-version 3.12 repro.py

Expected Behavior

An error on the ClassK line, as in mypy ≤ 2.3.0. CPython itself rejects the declaration at runtime (TypeError: A single constraint is not allowed / empty constraints), and pyright 1.1.414, pyrefly 1.3.2, ty 0.0.86 and zuban 0.10.0 all report it.

Actual Behavior

mypy 2.4.0:

repro.py:4: error: Type variable must have at least two constrained types  [misc]
Found 1 error in 1 file (checked 1 source file)

(only ClassL; ClassK on line 1 is silently accepted)

mypy 2.3.0:

repro.py:1: error: Type variable must have at least two constrained types  [misc]
repro.py:4: error: Type variable must have at least two constrained types  [misc]
Found 2 errors in 1 file (checked 1 source file)

This also flips the typing conformance test generics_syntax_declarations.py (line 60, class ClassK[T: ()]: # E) from automated Pass (mypy 2.1.0, as in the published results) to Fail with 2.4.0.

Your Environment

  • Mypy version used: 2.4.0 (compiled: yes); compared against 2.1.0 / 2.2.0 / 2.3.0 in separate venvs
  • Mypy command-line flags: --python-version 3.12 (also reproduces with no flags)
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.12.15, macOS arm64
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)
102

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.