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
Property setter parameter type-checked against getter return type instead of setter parameter type #12900
Bug Report
As shown in the code under To Reproduce, mypy checks the value that is set on an attribute not against that attribute's setter's parameter type (Iterable[Member]), but against the getter's return type (List[Member]). While it may not be common for a setter to accept a supertype of the type returned by the getter, or even a completely unrelated and incompatible type, there are valid reasons to do so and mypy should not make the assumption that both types are identical.
To Reproduce
fromtypingimportList, IterableclassMember:
passclassGroup:
@propertydefmembers(self) ->List[Member]:
pass@members.setterdefmembers(self, members: Iterable[Member]) ->None:
passgroup=Group()
group.members= {Member(), Member()}
# mypy error: test.py:19: error: Incompatible types in assignment (expression has type "Set[Member]", variable has type "List[Member]")
Expected Behavior
No errors raised by mypy at all.
Actual Behavior
mypy erraneously flags the type of the value set on the attribute as incompatible.
Your Environment
Mypy version used: 0.950
Mypy command-line flags: N/A
Mypy configuration options from mypy.ini (and other config files):
Activity
tmke8 commentedon May 30, 2022
Duplicate of #3004 I think. There was a PR to implement it here: #11643 but it wasn't merged.
bartfeenstra commentedon Jun 1, 2022
Aaah, I couldn't find anything earlier. Thanks for digging that up and linking it 👍 I'll close this issue in favor of #3004.