Ordered dataclass that inherits from abstract set produces (incorrect) errors
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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?
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 minimale dataclass-Beispiel mit mypy 0.910 auszuführen, und vergleiche dann seine Diagnosen mit den im Issue beschriebenen Fällen order=False und Mapping. Verfolge, wie abstrakte Set- und MutableSet-Methoden mit der dataclass-Reihenfolge interagieren. Als erledigt gilt die Aufgabe, wenn der Reproducer die inkorrekten Fehler nicht mehr erzeugt, während echte Fehler bei abstrakten Klassen und Überschreibungen bestehen bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100