Support exhaustiveness checking of single enumerable properties
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Feature
Support exhaustiveness checking of single boolean and enum properties and attributes of objects.
Pitch
The proposal is to improve exhaustiveness checking by supporting properties/attributes on a matched object. While it would be amazing to have infinitely nested support for this, I think we can recognize that there is value in supporting just single-level enumerable attributes.
In this example mypy isn't currently recognizing that all possible variations of Foo are handled, and gives an error on the assert_never().
from typing import assert_never
class Sentinel: ...
class Foo:
prop: bool
val: Foo | Sentinel
match val:
case Sentinel():
...
case Foo(prop=True):
...
case Foo(prop=False):
...
case no_match:
assert_never(no_match) # Currently a false positive here, no_match should be <nothing>.
https://mypy-play.net/?mypy=latest&python=3.11&gist=1edcb8f3ea56334662ed2036404563a1
Likewise, if the feature is accepted, we should expect an unreachable error for the third case in this example.
from typing import assert_never
class Foo:
prop: bool
val: Foo
match val:
case Foo(prop=True):
...
case Foo(prop=False):
...
case Foo():
... # Currently a false negative here, should be unreachable.
https://mypy-play.net/?mypy=latest&python=3.11&gist=74b23b6868c0c52056be1ade612b3052
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con i due esempi di match di Python e le relative riproduzioni collegate in mypy-play. Definisci il comportamento in termini di esaustività e di casi irraggiungibili per le proprietà booleane e le proprietà di tipo enum a un solo livello, quindi verifica che vengano corretti i risultati false-positive e false-negative descritti nell’issue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100