Skip to content

Args to __new__ not recognized #982

@gvanrossum

Description

@gvanrossum

I have this code:

class C(object):
    def __new__(cls, foo=None):
        obj = object.__new__(cls)
        obj.foo = foo
        return obj

x = C(foo=12)
print(x.foo)
y = C(12)

This elicits an error complaining about the foo keyword to C, another about the foo attribute, and then one about the positional argument:

mypy_new.py:7: error: Unexpected keyword argument "foo" for "C"
mypy_new.py:8: error: "C" has no attribute "foo"
mypy_new.py:9: error: Too many arguments for "C"

This may be related to #794 -- feel free to close as a dupe if fixing that would automatically fix this. (There seem to be two separate issues here -- it doesn't turn the __new__ signature into the class signature, and it doesn't believe attributes set by __new__ become attributes of the object.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions