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

Extended type narrowing for the X is L and X is not L type guard … #9759

Merged
merged 1 commit into from
Jan 25, 2025

Conversation

erictraut
Copy link
Collaborator

…pattern. Previously, narrowing was performed only when L was an enum or bool literal. Narrowing is also now applied for other literal types but only in the positive (if) direction. This addresses #9758.

…pattern. Previously, narrowing was performed only when `L` was an enum or bool literal. Narrowing is also now applied for other literal types but only in the positive (`if`) direction. This addresses #9758.
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

xarray (https://github.com/pydata/xarray)
-   /tmp/mypy_primer/projects/xarray/xarray/namedarray/core.py:151:24 - error: Argument of type "_DimsLike | _Dims | Default" cannot be assigned to parameter "dims" of type "_DimsLike" in function "__init__"
-     Type "_DimsLike | _Dims | Default" is not assignable to type "_DimsLike"
-       Type "Default" is not assignable to type "_DimsLike"
-         "Default" is not assignable to "str"
-         "Default" is incompatible with protocol "Iterable[_Dim]"
-           "__iter__" is not present (reportArgumentType)
-   /tmp/mypy_primer/projects/xarray/xarray/tests/test_namedarray.py:437:39 - error: Argument of type "_DimsLike | _Dims | Default" cannot be assigned to parameter "dims" of type "_DimsLike" in function "__init__"
-     Type "_DimsLike | _Dims | Default" is not assignable to type "_DimsLike"
-       Type "Default" is not assignable to type "_DimsLike"
-         "Default" is not assignable to "str"
-         "Default" is incompatible with protocol "Iterable[_Dim]"
-           "__iter__" is not present (reportArgumentType)
-   /tmp/mypy_primer/projects/xarray/xarray/tests/test_namedarray.py:498:39 - error: Argument of type "_DimsLike | _Dims | Default" cannot be assigned to parameter "dims" of type "_DimsLike" in function "__init__"
-     Type "_DimsLike | _Dims | Default" is not assignable to type "_DimsLike"
-       Type "Default" is not assignable to type "_DimsLike"
-         "Default" is not assignable to "str"
-         "Default" is incompatible with protocol "Iterable[_Dim]"
-           "__iter__" is not present (reportArgumentType)
- 2476 errors, 93 warnings, 0 informations 
+ 2473 errors, 93 warnings, 0 informations 

@erictraut erictraut merged commit c9d4475 into main Jan 25, 2025
18 checks passed
@erictraut erictraut deleted the issue-9758 branch January 25, 2025 17:01
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.

1 participant