Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen Anfängerfreundlich
#22,176 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@CheerathAniketh arbeitet bereits daran.

Seit 11.10.2026.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend, testing-qa

Rechercherichtung

Beginne mit dem Conformance-Test generics_syntax_declarations.py in Zeile 60, der bereits einen Fehler für class ClassK[T: ()] erwartet. Vergleiche sein Ergebnis mit mypy 2.3.0 und 2.4.0 und verfolge anschließend die Behandlung leerer Constraints für PEP-695-Typparameter. Fertig ist die Arbeit, wenn der Test in 2.4.0 den erwarteten Fehler „at least two constrained types“ meldet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
Python
Sterne
20.7k
Forks
3.3k
Ø Merge
2 T. 1 Std.
Gemergte PRs (30 T.)
104

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/mypy

Alle Issues in python/mypy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.