Skip to content

typing an init parameter causes wrong argument calculation #4290

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
mckaysalisbury opened this issue Nov 29, 2017 · 3 comments
Closed

typing an init parameter causes wrong argument calculation #4290

mckaysalisbury opened this issue Nov 29, 2017 · 3 comments

Comments

@mckaysalisbury
Copy link

I've got a class which has a method that creates instances of the class.

class Bar:
    @classmethod
    def create(cls, foo: int):
        return cls(foo)

    def __init__(self, foo: int) -> None:
        pass

When I run mypy against it, it says mypytest.py:4: error: Too many arguments for "Bar"

It seems like a bug to me, because this works fine

class Bar:
    @classmethod
    def create(cls, foo):
        return cls(foo)

    def __init__(self, foo: int) -> None:
        pass

I don't understand why a class method which defines the type of a parameter should break the creation of an instance.

(see https://stackoverflow.com/q/47493293/8384 )

@gvanrossum
Copy link
Member

This is because mypy processes definitions in order, and when it comes across create() in the first version it hasn't seen the __init__() signature yet. IIRC there's another issue open for this.

@JelleZijlstra
Copy link
Member

Yes, this is #1727.

@mvoitko
Copy link

mvoitko commented Oct 12, 2020

The same problem remains with SQLAlchemy models.

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

4 participants