Regression in 2.4.0: empty constraint tuple in PEP 695 type parameter (`class C[T: ()]`) is no longer reported
維護者通常 1 天內回覆
@CheerathAniketh 已經在處理了。
開始於 2026年10月11日。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
- 領域
- backend, testing-qa
研究方向
從第 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 內容生成。
描述
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
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/mypy 的其他 Issue
-
T-string below Python 3.14 also reports import-not-found for string.templatelib on line 1可能已有人在做 @jw9829 今天認領。 未關閉bug topic-parser
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
`stubgen --inspect-mode` crashes with `AttributeError on PEP 604 union syntax (X | Y)` *(mypy 2.1.0)*可能已有人在做 @ayushdoesdev 於 69 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
Inconsistent description of `strict_optional`可能已有人在做 @Joosboy 於 86 天前認領。 未關閉documentation
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
Cannot set `output` in `mypy.ini`可能重新可做 關聯的 PR 已關閉且未合併。 未關閉bug topic-configuration topic-error-reporting
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
相似的 Issue
-
bug
難度 1/5 1 小時以內 新手友好度 88/100
openwisp/openwisp-utils#777 ·
-
難度 2/5 1-3 小時 新手友好度 63/100
google-research/weatherbenchX#310 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
huggingface/peft#3955 ·
維護者通常 1 天內回覆
-
author-page correction
難度 2/5 1-3 小時 新手友好度 60/100
acl-org/acl-anthology#10313 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
AOSSIE-Org/Gitcord-GithubDiscordBot#147 · 1 則留言 ·
維護者通常 1 天內回覆