Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#22,176 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@CheerathAniketh ci sta già lavorando.

Dal 11/10/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia con il test di conformità generics_syntax_declarations.py alla riga 60, che si aspetta già un errore per class ClassK[T: ()]. Confronta il risultato con mypy 2.3.0 e 2.4.0, quindi esamina la gestione dei vincoli vuoti per i parametri di tipo PEP 695. Il lavoro è terminato quando il test segnala l’errore previsto “at least two constrained types” in 2.4.0.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
20.7k
Fork
3.3k
Merge medio
1g 20h
PR unite (30g)
102

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.