Bad error message while checking subclass of generic classes
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
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
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 mypy sullo script minimale nell’issue e conferma la diagnostica confusa di yield. Non viene indicato alcun file del repository né alcun test; traccia la diagnostica dal punto di ingresso del comando mypy, quindi verifica che la sottoclasse generica specificata in modo errato produca un messaggio utilizzabile che identifichi l’ereditarietà mancante da Generic[T].
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- 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