Ordered dataclass that inherits from abstract set produces (incorrect) errors
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
Hi, I am running mypy 0.910 and have the following code:
from collections.abc import Set
from dataclasses import dataclass
@dataclass(order=True)
class MySet(Set):
pass
And here are the errors it produces:
test.py: error: You may not have a custom __lt__ method when order=True
test.py: error: You may not have a custom __gt__ method when order=True
test.py: error: You may not have a custom __le__ method when order=True
test.py: error: You may not have a custom __ge__ method when order=True
test.py:5: error: Only concrete class can be given where "Type[MySet]" is expected
test.py:6: error: Argument 1 of "__lt__" is incompatible with supertype "AbstractSet"; supertype defines the argument type as "AbstractSet[Any]"
test.py:6: note: This violates the Liskov substitution principle
test.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
test.py:6: error: Argument 1 of "__gt__" is incompatible with supertype "AbstractSet"; supertype defines the argument type as "AbstractSet[Any]"
test.py:6: error: Argument 1 of "__le__" is incompatible with supertype "AbstractSet"; supertype defines the argument type as "AbstractSet[Any]"
test.py:6: error: Argument 1 of "__ge__" is incompatible with supertype "AbstractSet"; supertype defines the argument type as "AbstractSet[Any]"
Found 9 errors in 1 file (checked 1 source file)
Setting order=False gets rid of all errors except this one:
test.py:5: error: Only concrete class can be given where "Type[MySet]" is expected
It also seems to be related to Set and MutableSet from collections.abc. I don't get this behavior with Mapping for example.
Any ideas what is happening here?
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 eseguendo l’esempio minimo di dataclass con mypy 0.910, quindi confronta le relative diagnosi con i casi order=False e Mapping descritti nell’issue. Traccia il modo in cui i metodi astratti di Set e MutableSet interagiscono con l’ordinamento di dataclass. Il lavoro è completato quando il reproducer non produce più gli errori errati, mentre rimangono gli errori effettivi di classe astratta e di override.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools, tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100