Skip to content

classmethod of a generic class can't be called through an instance #1386

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
rwbarton opened this issue Apr 15, 2016 · 2 comments
Closed

classmethod of a generic class can't be called through an instance #1386

rwbarton opened this issue Apr 15, 2016 · 2 comments
Labels
bug mypy got something wrong

Comments

@rwbarton
Copy link
Contributor

I came across this while looking at #1337, but this is a separate issue.

from typing import TypeVar, Generic
T = TypeVar('T')
class A(Generic[T]):
    @classmethod
    def foo(cls, x: int) -> int: pass
    @staticmethod
    def bar(x: int) -> int: pass

a = A()  # type: A[str]
a.foo(2) # E: Invalid class method type
a.bar(2) # ok

If the class A is not generic, then both calls are accepted. So I think this is a bug.

The error arises in check_method_type when checking that the type of the instance (a) matches the return type of the argument cls as a Callable. But the latter type here is A[T-1], while the type of aisA[str]`.

@JukkaL JukkaL added the bug mypy got something wrong label Apr 15, 2016
@JukkaL
Copy link
Collaborator

JukkaL commented Apr 15, 2016

I don't see why both methods shouldn't be accepted, so this looks like a bug.

@gvanrossum gvanrossum added this to the 0.4.x milestone Apr 28, 2016
@gvanrossum
Copy link
Member

I can't repro this any more. I guess it's been fixed. Closing.

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

No branches or pull requests

3 participants