Description
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.