-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix two type inference bugs related to enum value attributes #12054
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
Closed
Conversation
This file contains hidden or 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
A few bugs in type operations were exposed by #11962. This fixes them. Fix #12051, but other use cases are affected as well. First, when we erase last known values in an union with multiple Instance types, make sure that the resulting union doesn't have duplicate erased types. The duplicate items weren't incorrect as such, but they could cause overly complex error messages and potentially slow type checking performance. Second, make the join of a union type and Any commutative. Previously the result dependend on the order of the operands, which was clearly incorrect.
sobolevn
approved these changes
Jan 24, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Diff from mypy_primer, showing the effect of this PR on open source code: steam.py (https://github.com/Gobot1234/steam.py)
- steam/invite.py:74: error: Argument 1 to "append" of "list" has incompatible type "Union[User, SteamID]"; expected "User" [arg-type]
+ steam/invite.py:74: error: Argument 1 to "append" of "list" has incompatible type "SteamID"; expected "User" [arg-type]
- steam/state.py:650: error: Argument "participant" to "DMChannel" has incompatible type "Union[User, SteamID]"; expected "User" [arg-type]
+ steam/state.py:650: error: Argument "participant" to "DMChannel" has incompatible type "SteamID"; expected "User" [arg-type]
- steam/ext/commands/converters.py:352: error: Argument 2 to "convert" of "ClanConverter" has incompatible type "Optional[int]"; expected "str" [arg-type]
+ steam/ext/commands/converters.py:352: error: Argument 2 to "convert" of "ClanConverter" has incompatible type "int"; expected "str" [arg-type]
jax (https://github.com/google/jax)
- jax/_src/dispatch.py:609: error: Item Device? of "Optional[Device?]" has no attribute "id" [union-attr]
- jax/_src/dispatch.py:609: error: Item "None" of "Optional[Device?]" has no attribute "id" [union-attr]
pip (https://github.com/pypa/pip)
+ src/pip/_internal/resolution/resolvelib/requirements.py:49: error: Cannot determine type of "_ireq"
+ src/pip/_internal/resolution/resolvelib/requirements.py:54: error: Cannot determine type of "_ireq"
+ src/pip/_internal/resolution/resolvelib/requirements.py:59: error: Cannot determine type of "_ireq"
+ src/pip/_internal/resolution/resolvelib/requirements.py:60: error: Cannot determine type of "_ireq"
+ src/pip/_internal/resolution/resolvelib/requirements.py:64: error: Cannot determine type of "_extras"
+ src/pip/_internal/resolution/resolvelib/requirements.py:81: error: Cannot determine type of "_ireq"
+ src/pip/_internal/resolution/resolvelib/requirements.py:91: error: Cannot determine type of "_ireq"
+ src/pip/_internal/resolution/resolvelib/requirements.py:92: error: Cannot determine type of "_ireq"
xarray (https://github.com/pydata/xarray)
+ xarray/core/dataset.py:228: error: Incompatible types in assignment (expression has type "List[Hashable]", variable has type "Hashable") [assignment]
+ xarray/core/dataset.py:228: note: Following member(s) of "List[Hashable]" have conflicts:
+ xarray/core/dataset.py:228: note: __hash__: expected "Callable[[], int]", got "None"
+ xarray/core/dataset.py:235: error: "Hashable" has no attribute "__iter__" (not iterable) [attr-defined]
+ xarray/core/dataset.py:260: error: Argument 1 to "len" has incompatible type "Hashable"; expected "Sized" [arg-type]
+ xarray/core/dataset.py:261: error: Value of type "Hashable" is not indexable [index]
+ xarray/core/dataset.py:264: error: "Hashable" has no attribute "__iter__" (not iterable) [attr-defined]
+ xarray/core/dataset.py:279: error: Argument 1 to "extend" of "list" has incompatible type "Hashable"; expected "Iterable[Hashable]" [arg-type]
|
I'll need to investigate the mypy primer output. |
JukkaL
added a commit
that referenced
this pull request
Jan 25, 2022
When we erase last known values in an union with multiple Instance types, make sure that the resulting union doesn't have duplicate erased types. The duplicate items weren't incorrect as such, but they could cause overly complex error messages and potentially slow type checking performance. This is one of the fixes extracted from #12054. Since some of the changes may cause regressions, it's better to split the PR. Work on #12051. Co-authored-by: Nikita Sobolev <[email protected]>
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.
A few bugs in type operations were exposed by #11962. This fixes
them.
Fix #12051, but other use cases are affected as well.
First, when we erase last known values in an union with multiple
Instance types, make sure that the resulting union doesn't have
duplicate erased types. The duplicate items weren't incorrect as such,
but they could cause overly complex error messages and potentially
slow type checking performance.
Second, make the join of a union type and Any commutative.
Previously the result dependend on the order of the operands,
which was clearly incorrect.