-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improved handling of types float
and complex
, which are special-c…
#6013
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ased in PEP 484 as "promotion types". The new logic now properly models the runtime behavior for `isinstance` and class pattern matching when used with these promotion types. This addresses #6008.
Diff from mypy_primer, showing the effect of this PR on open source code: AutoSplit (https://github.com/Toufool/AutoSplit)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:806:17 - error: Type of "pause_times" is partially unknown
+ Type of "pause_times" is "list[AutoSplit | float | Unknown]" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:308:9 - error: Type of "start_image_threshold" is partially unknown
+ Type of "start_image_threshold" is "AutoSplit | float | Unknown" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:317:66 - error: Argument type is partially unknown
+ Argument corresponds to parameter "value" in function "decimal"
+ Argument type is "AutoSplit | float | Unknown" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:325:9 - error: Type of "similarity_diff" is partially unknown
+ Type of "similarity_diff" is "float | Unknown" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:551:31 - error: Argument type is partially unknown
+ Argument corresponds to parameter "stop_time" in function "__pause_loop"
+ Argument type is "AutoSplit | float | Unknown" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:619:34 - error: Argument type is partially unknown
+ Argument corresponds to parameter "stop_time" in function "__pause_loop"
+ Argument type is "AutoSplit | float | Unknown" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:804:17 - error: Type of "threshold" is partially unknown
+ Type of "threshold" is "AutoSplit | float | Unknown" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:809:62 - error: Argument type is partially unknown
+ Argument corresponds to parameter "__iterable" in function "max"
+ Argument type is "list[AutoSplit | float | Unknown]" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:809:17 - error: Type of "paused" is partially unknown
+ Type of "paused" is "bool | Unknown" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:814:21 - error: Type of "should_reset" is partially unknown
+ Type of "should_reset" is "bool | Unknown" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:820:72 - error: Argument type is partially unknown
+ Argument corresponds to parameter "value" in function "decimal"
+ Argument type is "AutoSplit | float | Unknown" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplit.py:851:66 - error: Argument type is partially unknown
+ Argument corresponds to parameter "value" in function "decimal"
+ Argument type is "AutoSplit | float | Unknown" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplitImage.py:78:26 - error: Cannot access member "settings_dict" for type "int"
+ Member "settings_dict" is unknown (reportGeneralTypeIssues)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplitImage.py:76:9 - error: Type of "default_value" is partially unknown
+ Type of "default_value" is "AutoSplit | float | Unknown" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplitImage.py:71:26 - error: Cannot access member "settings_dict" for type "int"
+ Member "settings_dict" is unknown (reportGeneralTypeIssues)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplitImage.py:69:9 - error: Type of "default_value" is partially unknown
+ Type of "default_value" is "AutoSplit | float | Unknown" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplitImage.py:72:16 - error: Return type, "AutoSplit | float | Unknown", is partially unknown (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplitImage.py:67:9 - error: Return type, "AutoSplit | float | Unknown", is partially unknown (reportUnknownParameterType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplitImage.py:79:16 - error: Return type, "AutoSplit | float | Unknown", is partially unknown (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/AutoSplit/src/AutoSplitImage.py:74:9 - error: Return type, "AutoSplit | float | Unknown", is partially unknown (reportUnknownParameterType)
+ /tmp/mypy_primer/projects/AutoSplit/src/menu_bar.py:181:21 - error: Argument type is partially unknown
+ Argument corresponds to parameter "value" in function "decimal"
+ Argument type is "AutoSplit | float | Unknown" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/AutoSplit/src/menu_bar.py:186:21 - error: Argument type is partially unknown
+ Argument corresponds to parameter "value" in function "decimal"
+ Argument type is "AutoSplit | float | Unknown" (reportUnknownArgumentType)
- 486 errors, 30 warnings, 7 informations
+ 508 errors, 30 warnings, 7 informations
|
@erictraut Is that mypy_primer result expected? If so, why does a |
Yes, this is expected. This code sample should make it clear why def func(x: float | str):
if isinstance(x, float):
print('received a float!')
else:
reveal_type(x) # int | str
# The following line is a type violation because `x` is
# is possibly an `int`.
return x.upper()
func(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…ased in PEP 484 as "promotion types". The new logic now properly models the runtime behavior for
isinstance
and class pattern matching when used with these promotion types. This addresses #6008.