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

Synonyms for @property properties not handled correctly #15054

Closed
MartinBonner opened this issue Apr 14, 2023 · 2 comments
Closed

Synonyms for @property properties not handled correctly #15054

MartinBonner opened this issue Apr 14, 2023 · 2 comments
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes

Comments

@MartinBonner
Copy link

Bug Report

Given a member function decorated with @property, a synonym created by assignment is not recognized as a property. Instead it is considered a function.

To Reproduce
Consider the following python script:

class Class:
    @property
    def my_function(self) -> int:
        return 42

    my_f = my_function

c = Class()
i: int = c.my_f
print(i)

Running it prints 42 (and not <bound method Class.my_function of <__main__.Class object at 0x7f60f14d8460>>).

Expected Behavior
mypy should report Success: no issues found in 1 source file

Actual Behavior
mypy reports:

mjb.py:9: error: Incompatible types in assignment (expression has type "Callable[[], int]", variable has type "int")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Workround

If the penultimate line is changed to i: int = c.my_function mypy accepts it with no errors.

Your Environment

  • Mypy version used: 1.2.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.5

Motivating use case

One obvious answer to this is "don't create such damn-fool aliases in the first place". However we ran into the underlying problem because the git module does exactly this, and we happened to use Repo.refs rather than Repo.references. As noted in the workround, changing to Repo.references worked.

@MartinBonner MartinBonner added the bug mypy got something wrong label Apr 14, 2023
@AlexWaygood AlexWaygood added the topic-descriptors Properties, class vs. instance attributes label Apr 14, 2023
@AlexWaygood
Copy link
Member

Duplicate of #6700

@AlexWaygood AlexWaygood marked this as a duplicate of #6700 Apr 14, 2023
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2023
@MartinBonner
Copy link
Author

Sorry for the noise. I did search for @property but didn't find that ticket 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes
Projects
None yet
Development

No branches or pull requests

2 participants