You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mypy seems to forget about the @property decorator if the property is aliased.
To Reproduce
classMyClass:
deferror(self) ->bool:
# Incompatible return value type (got "Callable[[], bool]", expected "bool") [return-value]returnself.prop_aliasdefworks(self) ->bool:
# No errorreturnself.prop@propertydefprop(self) ->bool:
returnTrueprop_alias=propsome_boolean: boolinstance=MyClass()
# Incompatible types in assignment (expression has type "Callable[[], bool]", variable has type "bool") [assignment]some_boolean=instance.prop_alias# No errorsome_boolean=instance.prop
Expected Behavior
prop_alias should be usable as a boolean, just like prop
Actual Behavior
prop_alias is seen as a Callable
Your Environment
Mypy version used: 0.982 (compiled: yes)
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files):
classFoo:
@propertydefbar(self):
return42baz=barx: int=Foo().bar# works# x: int = Foo().baz # error: Incompatible types in assignment (expression has type "Callable[[], Any]", variable has type "int") [assignment]
Activity
[-]`@property` alias is typed as `Callable`[/-][+]Reassigend `@property` is typed as `Callable`[/+][-]Reassigend `@property` is typed as `Callable`[/-][+]Reassigned `@property` is typed as `Callable`[/+]niklasmohrin commentedon Jan 16, 2023
Same behavior on
without config. Result:
finite-state-machine commentedon Jan 26, 2024
Issue is confirmed to affect both 1.8 and master.
mypy-play.net gist
finite-state-machine commentedon Jan 26, 2024
This might be the same as #6700.
Avasam commentedon Jan 26, 2024
You are right. Closing as duplicate
Update mypy issue reference to duplicated original issue
Update mypy issue reference to duplicated original issue (#11320)