-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Type is not infered from default value of dict.get() #10890
Comments
Isn't this because |
The declared type of |
This is another thing that stems from mypy's notion of "type context". If you use a new variable, you get the result you want, i.e.:
|
mapping[v] if v in mapping else v and mapping.get(v, v) are basically the same thing so I would expect mypy to infer the same type for the return value in both cases. |
It seems mypy doesn't understand the star expansion: mkosi/__init__.py:6766:26: error: List or tuple expected as variable arguments [misc] FIRMWARE_LOCATIONS = [ ^ Found 1 error in 1 file (checked 3 source files) There's a similar bug open upstream (python/mypy#10890), so I hope this will be fixed, and then this commit can be reverted.
Fixed in #14151 |
Bug Report
When using
dict.get(value, default)
the returned type is not inferred correctly if the value was initially declared asOptional
.To Reproduce
Expected Behavior
Revealed type is
builtins.str
.Actual Behavior
Revealed type is
Union[builtins.str, None]
.Your Environment
mypy.ini
(and other config files): --The text was updated successfully, but these errors were encountered: