Bad error message while checking subclass of generic classes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running mypy on the minimal script in the issue and confirm the confusing yield diagnostic. No repository file or test is named; trace the diagnostic from the mypy command entry point, then verify that the misspecified generic subclass produces an actionable message identifying the missing Generic[T] inheritance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100