Fix overload selection with nested Any and object fallback - #4533
Open
ting-hong-shieh wants to merge 2 commits into
Open
Fix overload selection with nested Any and object fallback#4533ting-hong-shieh wants to merge 2 commits into
ting-hong-shieh wants to merge 2 commits into
Conversation
Prefer a specific overload over later object fallbacks when only nested gradual types create ambiguity in compatibility mode. Keep top-level Any ambiguous and leave spec-compliant overload evaluation unchanged.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D115850637. (Because this pull request was imported automatically, there will not be any future comments.) |
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: ============================================================
SUMMARY
============================================================
Total: +11 new errors, -24 fixed errors
Projects with changes (3):
scipy: +1 -1
scikit-learn: +0 -3
pandas: +10 -20
============================================================
FULL DIFF DETAILS
------------------------------------------------------------
scipy (https://github.com/scipy/scipy)
- ERROR scipy/signal/_spectral_py.py:231:13-57: Implicit conversion of `numpy.bool | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR scipy/signal/_spectral_py.py:231:13-57: Implicit conversion of `numpy.bool` to `bool` is not allowed [implicit-bool]
scikit-learn (https://github.com/scikit-learn/scikit-learn)
- ERROR sklearn/decomposition/_nmf.py:395:19-57: The type of `permutation` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR sklearn/feature_extraction/text.py:1310:21-63: The type of `j_indices` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR sklearn/neighbors/_classification.py:306:20-59: The type of `mode` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
pandas (https://github.com/pandas-dev/pandas)
- ERROR pandas/core/arrays/sparse/array.py:2151:8-24: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:492:16-30: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:509:20-34: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:574:16-30: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:589:16-30: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:589:16-73: Implicit conversion of `Literal[False] | NDFrame | numpy.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/arrays/string_.py:589:16-73: Implicit conversion of `Literal[False] | numpy.bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/arrays/string_.py:887:20-28: Object of class `bool` has no attribute `any` [missing-attribute]
+ ERROR pandas/core/arrays/string_.py:887:20-30: Implicit conversion of `numpy.bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/dtypes/cast.py:1422:8-53: Implicit conversion of `Literal[0] | NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/dtypes/cast.py:1422:8-53: Implicit conversion of `Literal[0] | bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/dtypes/cast.py:1429:16-27: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/indexes/multi.py:4243:28-36: Implicit conversion of `signedinteger[_NBitIntP] | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/indexes/multi.py:4243:28-36: Implicit conversion of `signedinteger[_NBitIntP]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/indexes/multi.py:4253:28-36: Implicit conversion of `signedinteger[_NBitIntP] | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/indexes/multi.py:4253:28-36: Implicit conversion of `signedinteger[_NBitIntP]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/indexing.py:3893:16-29: Implicit conversion of `Literal[False] | numpy.bool | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/indexing.py:3893:16-29: Implicit conversion of `Literal[False] | numpy.bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/internals/construction.py:413:16-48: Implicit conversion of `Literal[False] | ndarray[tuple[Any, ...], dtype[numpy.bool]] | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/internals/construction.py:413:16-48: Implicit conversion of `Literal[False] | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/nanops.py:369:24-40: Implicit conversion of `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` to `bool` is not allowed [implicit-bool]
- ERROR pandas/core/strings/accessor.py:731:16-34: Implicit conversion of `numpy.bool | Unknown` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/core/strings/accessor.py:731:16-34: Implicit conversion of `numpy.bool` to `bool` is not allowed [implicit-bool]
- ERROR pandas/io/pytables.py:5980:8-16: Object of class `bool` has no attribute `any` [missing-attribute]
+ ERROR pandas/io/pytables.py:5980:8-18: Implicit conversion of `numpy.bool` to `bool` is not allowed [implicit-bool]
+ ERROR pandas/io/pytables.py:5980:8-38: Implicit conversion of `builtins.bool | numpy.bool | Unknown` to `bool` is not allowed [implicit-bool]
- ERROR pandas/io/pytables.py:5986:45-49: Argument `NDFrame | builtins.bool | ndarray[tuple[Any, ...], dtype[numpy.bool]]` is not assignable to parameter `mask` with type `ndarray` in function `_make_index_nan_rep` [bad-argument-type]
- ERROR pandas/io/pytables.py:5987:38-43: Unary `~` is not supported on `bool` [deprecated]
- ERROR pandas/plotting/_matplotlib/hist.py:102:18-39: The type of `values` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR pandas/plotting/_matplotlib/hist.py:104:39-45: The type of this argument is unknown [unknown-argument-type] |
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
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.
Summary
objectfallback when nested gradual types create ambiguity in compatibility modeAnyambiguous and preserve spec-compliant overload behaviorRoot cause
Overload evaluation materialized the nested
Anyin the argument during step 5. The materialized argument could no longer select the bounded generic overload, so the laterobjectfallback remained in the candidate set. Because the two overloads had incompatible return types, the call resolved toUnknown.Validation
cargo test test::overload(117 passed)python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschemagit diff --checkFixes #3977