Skip to content

Incorrect type inferred for @property decorated functions #7974

Closed
@mthuurne

Description

@mthuurne

When mypy 0.740 is run on the following code:

class C:
    @property
    def prop(self) -> int:
        return 123

c = C()
print(c.prop)
getter = C.prop.__get__
print(getter(c))

It reports:

8: error: "Callable[[C], int]" has no attribute "__get__"

I think the problem is that, in general, mypy assumes decorators don't change the signature of the decorated function. When I ask it to reveal the type of C.prop, it reports def (self: testcase.C) -> builtins.int, which is the signature of the undecorated function, not of the property.

Since the property decorator is a built-in, it would be useful to have dedicated support for it in mypy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions