Exhaustiveness checks (assert_never) don't work with 2-tuple of enums
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
The code below fails to type check, but should succeed because it's exhaustive.
There are some possibly related issues, but I don't know if they are all the same bug, the other tickets tend to depend on Union which this does not: #16650 #15426 #12364
To Reproduce
Playground link: https://mypy-play.net/?mypy=latest&python=3.12&gist=0d21d288fce8aa13d3cc60f4e418960a
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from enum import Enum
from typing import assert_never
class A(Enum):
A0 = 0
A1 = 1
class B(Enum):
B0 = 0
B1 = 1
def test(a: A, b: B) -> bool:
match (a, b):
case (A.A0, B.B0):
return True
case (A.A0, B.B1):
return True
case (A.A1, B.B0):
return True
case (A.A1, B.B1):
return True
case _ as never:
assert_never(never)
return False
Actual Behavior
typecheck_test.py:26: error: Argument 1 to "assert_never" has incompatible type "tuple[A, B]"; expected "NoReturn" [arg-type]
Your Environment
- Mypy version used: 1.8.0
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini(and other config files): n/a - Python version used: 3.11 (but also happens with 3.12 in playground link)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das bereitgestellte Tupel-Beispiel mit zwei Enums im verlinkten mypy playground oder in einem lokalen mypy-Checkout zu reproduzieren. Untersuche anschließend den Pfad zur Exhaustivitätsprüfung für strukturelles Pattern Matching und assert_never. Erledigt ist die Aufgabe, wenn das Beispiel ohne den inkompatiblen Fehler tuple[A, B] typgeprüft wird und das bestehende Verhalten für nicht exhaustive Matches erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100