python / python/mypy

Improve error message for type-abstract errors

Open
#18,711 0 comments 1 reaction 1 assignee View on GitHub

@sobolevn is already working on this.

Since Feb 22, 2025.

feature topic-error-reporting
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature
Add more details to the [type-abstract] error message.

Pitch

If I have the following abstract base class

class BaseClass(abc.ABC):

    @abstractmethod
    def method1(self): ...

    @abstractmethod
    def method2(self): ...

    @abstractmethod
    def method3(self): ...

And later I make a subclass of that base class

class ExampleSubClass(BaseClass):

    def method1(self): ...

    def method2(self): ...

    #but I forgot to override method3

Then I will get the following error when I try to use ExampleSubClass in application code: Only concrete class can be given where "type[ExampleSubClass]" is expected [type-abstract]

It would be great if the error message specified why ExampleSubClass is not a concrete class. An ideal error message would look something like: "Only concrete class can be given where type[ExampleSubClass] is expected. ExampleSubClass has abstract methods [method3]"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.