Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad error message while checking subclass of generic classes #11040

Open
NicolaDonelli opened this issue Aug 31, 2021 · 0 comments
Open

Bad error message while checking subclass of generic classes #11040

NicolaDonelli opened this issue Aug 31, 2021 · 0 comments
Labels
bug mypy got something wrong topic-error-reporting How we report errors

Comments

@NicolaDonelli
Copy link

Bug Report

mypy command on a misspecified subclass of a generic class returns a pretty confusing error message (As per issue #8696)

To Reproduce

  1. 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
  1. 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
@NicolaDonelli NicolaDonelli added the bug mypy got something wrong label Aug 31, 2021
@AlexWaygood AlexWaygood added the topic-error-reporting How we report errors label Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-error-reporting How we report errors
Projects
None yet
Development

No branches or pull requests

2 participants