Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉 適合新手
#22,176 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@CheerathAniketh 已經在處理了。

開始於 2026年10月11日。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python

研究方向

從第 60 行的符合性測試 generics_syntax_declarations.py 開始,該測試已預期 class ClassK[T: ()] 會發生錯誤。比較它在 mypy 2.3.0 和 2.4.0 中的結果,接著追蹤 PEP 695 型別參數對空限制的處理。完成時,測試會在 2.4.0 中回報預期的 “at least two constrained types” 錯誤。

由索引模型根據 Issue 內容生成。

描述

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
主要語言
Python
星號
20.7k
分支
3.3k
平均合併
1 天 20 小時
30 天內合併 PR
102

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/mypy 的其他 Issue

查看 python/mypy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。