Skip to content
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
merged 1 commit into from
Sep 24, 2023

Conversation

erictraut
Copy link
Collaborator

…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.

…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.
@erictraut erictraut merged commit 90ad51a into main Sep 24, 2023
10 checks passed
@erictraut erictraut deleted the issue6008-2 branch September 24, 2023 00:39
@github-actions
Copy link
Contributor

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 

@Avasam
Copy link

Avasam commented Oct 3, 2023

@erictraut Is that mypy_primer result expected? If so, why does a isinstance condition results in an unknown type in the else branch for floats unions?

@erictraut
Copy link
Collaborator Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants