-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapping.get
overload has covariant type as argument
#9555
Comments
@srittau Looking at the example given in the PR m: Mapping[str, List[str]]
x = m.get('x', [])
reveal_type(x) # list[<nothing>] instead of list[str] it seems that the issue is that there is a reasonable expectation that for @overload # if _T ≤ _VT_co
def get(self, __key: _KT, default: _T) -> _VT_co: ...
@overload # else
def get(self, __key: _KT, default: _T) -> _T: ... |
@randolf-scholz If you want to write an exploratory PR that would certainly be welcome. We have a much better test infrastructure nowadays that allows us to judge the impact of any changes. |
@srittau I think with the current typing system it's unfortunately impossible. One would need something like TypeScript's Conditional Types |
typeshed/stdlib/typing.pyi
Lines 576 to 589 in 2b9f200
Shouldn't the second overload simply be
Why is there a covariant variable being used as a function input? Is there any case where this simplified signature would be incompatible with the current signature?
The text was updated successfully, but these errors were encountered: