Skip to content

classmethod defined before __init__ sees incorrect signature #3384

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
JelleZijlstra opened this issue May 19, 2017 · 1 comment
Closed

classmethod defined before __init__ sees incorrect signature #3384

JelleZijlstra opened this issue May 19, 2017 · 1 comment
Labels
bug mypy got something wrong priority-1-normal

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 19, 2017

class Foo:
    @classmethod
    def classm(cls, a: int, b: str) -> Foo:
        reveal_type(cls)  # E: Revealed type is 'def () -> classm.Foo'
        return cls(a, b)  # E: Too many arguments for "Foo"

    def __init__(self, a: int, b: str) -> None:
        self.a = a
        self.b = b

Apparently, we eagerly bind the cls parameter of a classmethod to the type as it exists when semanal.py visits the classmethod. If that is before __init__ has been defined, then we incorrectly infer that cls takes no arguments. It works as expected (no errors; reveal_type says cls takes two parameters) if I put classm after __init__.

@JelleZijlstra JelleZijlstra changed the title classmethod define before __init__ sees incorrect signature classmethod defined before __init__ sees incorrect signature May 19, 2017
@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal labels May 19, 2017
@JelleZijlstra
Copy link
Member Author

This is a dupe of #1727.

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

No branches or pull requests

2 participants