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

Incorrect type inferred for @property decorated functions #7974

Closed
mthuurne opened this issue Nov 19, 2019 · 1 comment
Closed

Incorrect type inferred for @property decorated functions #7974

mthuurne opened this issue Nov 19, 2019 · 1 comment

Comments

@mthuurne
Copy link
Contributor

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.

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 19, 2019

This is essentially a duplicate of #6185.

@JukkaL JukkaL closed this as completed Nov 19, 2019
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

2 participants