Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの 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 件 担当者 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時間
マージ済み PR(30日)
106

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/mypy のほかの issue

python/mypy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。