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
{{ message }}
Repository navigation
False positive violation when overriding attributes using descriptors #18695
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]
Activity
Use checkmember.py to check variable overrides (python#18847)