Skip to content

error: Return type of <functionName> incompatible with supertype <ClassName> #3576

Description

@YuvalPruss

I got a code that looks like this:

from typing import NamedTuple, Dict, Optional, List, Any


class Object1(object, metaclass=ABCMeta):
    def __init__(self) -> None:
        pass

    @abstractmethod
    def get_logo(self) -> Optional[str]:
        pass


class Object2(Object1):
    def __init__(self) -> None:
        super().__init__()

    async def get_logo(self) -> Optional[str]:
        return ''


class Object3(Object1):
    def __init__(self) -> None:
        super().__init__()

    async def get_logo(self) -> Optional[str]:
        return None

And the mypy alerts me that:

test.py:19: error: Return type of "get_logo" incompatible with supertype "Object1"
test.py:27: error: Return type of "get_logo" incompatible with supertype "Object1"

But it's look OK to me, because they return the same type...
I run it with: mypy --strict-optional --ignore-missing-imports <file>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions