Bad error message while checking subclass of generic classes
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
mypy command on a misspecified subclass of a generic class returns a pretty confusing error message (As per issue #8696)
To Reproduce
- Create a script containing this snippet:
from abc import ABC, abstractmethod
from typing import TypeVar, Iterable, Iterator
T = TypeVar('T')
class MyABC(ABC):
@property
@abstractmethod
def items(self) -> Iterable[T]: ...
def my_method(self) -> Iterator[T]:
for item in self.items:
yield item
- Run mypy on the created script
Expected Behavior
Since MyABC should inherit also from Generic[T] I'd expect that the error message would return something on the line of:
error: Incompatible types in "yield". The class should inherit from "Generic[T]"
Actual Behavior
The actual error message is:
error: Incompatible types in "yield" (actual type "T", expected type "T")
Environment
- Mypy version used: 0.910
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): default - Python version used: 3.6.5
- Operating system and version: MacOS BigSur 11.5.2
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, mypy für das minimale Skript im Issue auszuführen, und bestätige die verwirrende yield-Diagnose. Es wird keine Repository-Datei oder kein Test genannt; verfolge die Diagnose vom Einstiegspunkt des mypy-Befehls aus und überprüfe anschließend, dass die falsch spezifizierte generische Unterklasse eine verwertbare Meldung erzeugt, die die fehlende Vererbung von Generic[T] nennt.
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
- 35/100