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
Overriding an attribute with a descriptor causes mypy to be unable to verify compliance with the parent's attribute.
This is similar to #17513, but at the moment it appears this is a distinct problem caused by child classes using descriptors.
To Reproduce
from __future__ importannotationsfromabcimportABC, abstractmethodfromtypingimportoverload, TypeVar_T=TypeVar("_T")
classValue:
passclassContainerBase(ABC):
@property@abstractmethoddefvalue(self) ->Value:
passclassValueAttr:
@overloaddef__get__(self: _T, instance: None, owner: type[object]) ->_T:
pass@overloaddef__get__(self, instance: _T, owner: type[_T]) ->Value:
passdef__get__(self: _T, instance: object|None, owner: type[object]) ->Value|_T:
ifinstanceisNone:
returnselfreturnValue()
classContainer(ContainerBase):
value=ValueAttr()
# mypy says about the line above:# error: Incompatible types in assignment (expression has type "ValueAttr", base class "ContainerBase" defined the type as# "Value") [assignment]
Bug Report
Overriding an attribute with a descriptor causes mypy to be unable to verify compliance with the parent's attribute.
This is similar to #17513, but at the moment it appears this is a distinct problem caused by child classes using descriptors.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=bfbc9b2f6b26672a945ba5ab291a790b
Expected Behavior
No errors, and a
Container
instance'svalue
attribute should be of typeValue
.Actual Behavior
The error above, and a
Container
instance'svalue
attribute type is inferred asAny
.Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: