Skip to content

Propper inheritance with staticmethod #7466

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

Closed
InvisibleHandOfDoom opened this issue Sep 4, 2019 · 1 comment
Closed

Propper inheritance with staticmethod #7466

InvisibleHandOfDoom opened this issue Sep 4, 2019 · 1 comment

Comments

@InvisibleHandOfDoom
Copy link

If have following code

from typing import Type, TypeVar

T = TypeVar("T")

class Foo:
    @classmethod
    def load(cls: Type[T]) -> T: ...

class Bar(Foo):
    @classmethod
    def load(cls: Type[Bar]) -> Bar:
        return cls()

which, fails to type check, with:

test.pyi:11: error: Return type "Bar" of "load" incompatible with return type <nothing> in supertype "Foo"

To my confusion it type check if I modify parent signature to:

from typing import Type, TypeVar

T = TypeVar("T")

class Foo:
    @classmethod
    def load(cls: T) -> T: ...

class Bar(Foo):
    @classmethod
    def load(cls: Type[Bar]) -> Bar:
        return cls()
  • Mypy version mypy-0.730+dev.63380783f032ee17c8cf0560dd81cf734bf36103
  • No custom flags
@ilevkivskyi
Copy link
Member

Thanks for reporting!

This looks like another duplicate of #2511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants