Skip to content
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

Too many arguments for "__setattr__" of "object" on valid code #5794

Closed
tavianator opened this issue Oct 17, 2018 · 2 comments · Fixed by #7232
Closed

Too many arguments for "__setattr__" of "object" on valid code #5794

tavianator opened this issue Oct 17, 2018 · 2 comments · Fixed by #7232
Labels
bug mypy got something wrong priority-2-low

Comments

@tavianator
Copy link
Contributor

This code is a reasonable pattern for initializing "immutable" objects:

class Foo:
    def __new__(cls, bar: int):
        ret = super().__new__(cls)
        super().__setattr__(ret, "bar", bar)
        return ret

But mypy complains

foo.py:4: error: Too many arguments for "__setattr__" of "object"
@gvanrossum gvanrossum added bug mypy got something wrong priority-2-low labels Oct 17, 2018
@gvanrossum
Copy link
Member

This is another special case for __new__ that mypy misses -- in __new__, super() is a class object (its type is something like Type[B] where B is the base class -- if there are multiple base classes the type becomes more problematic).

In the grand scheme of things it doesn't feel like it's a big priority, though if you come up with a fix we'll take it!

@tavianator
Copy link
Contributor Author

This is actually broken for things other than __new__ too:

class Foo:
    @classmethod
    def create(cls, bar: int) -> "Foo":
        ret = cls.__new__(cls)
        super().__setattr__(ret, "bar", bar)
        return ret

I'll try to find a fix.

JukkaL pushed a commit that referenced this issue Jul 25, 2019
The previous implementation assumed that all super(T, x) expressions
were for instances of the current class.  This new implementation uses
the precise types of T and x to do a more accurate analysis.

Fixes #5794.
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-2-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants