Find precise fallback for ambiguous Any overloads - #22060
Open
ilevkivskyi wants to merge 3 commits into
Open
ilevkivskyi wants to merge 3 commits into
ilevkivskyi wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: colour (https://github.com/colour-science/colour)
- colour/io/luts/lut.py:1433: error: No overload variant of "pad" matches argument types "ndarray[Any, Any]", "tuple[int, Any | signedinteger[_8Bit] | signedinteger[_16Bit] | signedinteger[_32Bit] | signedinteger[_64Bit] | unsignedinteger[_8Bit] | unsignedinteger[_16Bit] | unsignedinteger[_32Bit] | unsignedinteger[_64Bit]]", "str", "float" [call-overload]
+ colour/io/luts/lut.py:1433: error: No overload variant of "pad" matches argument types "ndarray[tuple[Any, ...], dtype[float64 | Any]]", "tuple[int, Any | signedinteger[_8Bit] | signedinteger[_16Bit] | signedinteger[_32Bit] | signedinteger[_64Bit] | unsignedinteger[_8Bit] | unsignedinteger[_16Bit] | unsignedinteger[_32Bit] | unsignedinteger[_64Bit]]", "str", "float" [call-overload]
comtypes (https://github.com/enthought/comtypes)
- comtypes/_vtbl.py:430: error: Unused "type: ignore" comment [unused-ignore]
core (https://github.com/home-assistant/core)
+ homeassistant/components/upcloud/entity.py:68: error: Unused "type: ignore" comment [unused-ignore]
- homeassistant/components/enphase_envoy/coordinator.py:91: error: Returning Any from function declared to return "bool" [no-any-return]
discord.py (https://github.com/Rapptz/discord.py)
+ discord/ui/view.py:281: error: Item "Item[Any]" of "Item[Any] | Any" has no attribute "_children" [union-attr]
+ discord/ui/container.py:160: error: Item "Item[Any]" of "Item[Any] | Any" has no attribute "_children" [union-attr]
pydantic (https://github.com/pydantic/pydantic)
- pydantic/v1/generics.py:124: error: No overload variant of "create_model" matches argument types "str", "str", "tuple[Any, ...]", "None", "dict[str, classmethod[Any, Any, Any]]", "None", "dict[Any, tuple[DeferredType, FieldInfo]]" [call-overload]
+ pydantic/v1/generics.py:124: error: No overload variant of "create_model" matches argument types "str", "str", "tuple[type[GenericModelT] | type[Any], ...]", "None", "dict[str, classmethod[Any, Any, Any]]", "None", "dict[Any, tuple[DeferredType, FieldInfo]]" [call-overload]
scipy (https://github.com/scipy/scipy)
+ scipy/sparse/_sputils.py:498: error: Incompatible types in assignment (expression has type "tuple[int | Any, ...]", variable has type "tuple[int]") [assignment]
scikit-learn (https://github.com/scikit-learn/scikit-learn)
+ sklearn/linear_model/tests/test_ransac.py:26: error: Argument 1 to "__iadd__" of "ndarray" has incompatible type "ndarray[tuple[Any, ...], dtype[float64]]"; expected "_SupportsArray[dtype[numpy.bool[builtins.bool] | integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | integer[Any]]]] | int | _NestedSequence[int]" [arg-type]
+ sklearn/linear_model/tests/test_ransac.py:28: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[number[Any, float]]]", variable has type "ndarray[tuple[int], dtype[signedinteger[_32Bit | _64Bit]]]") [assignment]
+ sklearn/linear_model/tests/test_ransac.py:29: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[number[Any, float]]]", variable has type "ndarray[tuple[Any, ...], dtype[floating[Any]]]") [assignment]
tornado (https://github.com/tornadoweb/tornado)
+ tornado/test/httpclient_test.py:1015: error: Argument 1 to "fetch" of "AsyncHTTPTestCase" has incompatible type "**dict[str | Any, str | Any]"; expected "bool" [arg-type]
+ tornado/test/httpclient_test.py:1029: error: Argument 1 to "fetch" of "AsyncHTTPTestCase" has incompatible type "**dict[str | Any, str | Any]"; expected "bool" [arg-type]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/categorical.py:504: error: Item "ExtensionArray" of "Any | ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]]" has no attribute "_codes" [union-attr]
+ pandas/core/arrays/categorical.py:504: error: Item "ndarray[tuple[Any, ...], dtype[Any]]" of "Any | ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]]" has no attribute "_codes" [union-attr]
+ pandas/core/tools/datetimes.py:741: error: No overload variant of "__add__" of "Timestamp" matches argument type "ExtensionArray" [operator]
+ pandas/core/tools/datetimes.py:741: note: Possible overload variants:
+ pandas/core/tools/datetimes.py:741: note: def __add__(self, ndarray[tuple[Any, ...], dtype[Any]], /) -> ndarray[tuple[Any, ...], dtype[Any]]
+ pandas/core/tools/datetimes.py:741: note: def __add__(self, timedelta | timedelta64[Any] | Tick, /) -> Timestamp
+ pandas/core/tools/datetimes.py:741: error: Unsupported operand types for + ("NaTType" and "ExtensionArray") [operator]
+ pandas/core/tools/datetimes.py:741: note: Both left and right operands are unions
+ pandas/core/tools/datetimes.py:754: error: Argument 2 to "_coerce_origin_overflow" has incompatible type "Any | ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]]"; expected "TimedeltaArray" [arg-type]
+ pandas/core/internals/construction.py:909: error: Argument 1 to "vstack" has incompatible type "list[Any | ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]]]"; expected "Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]]]" [arg-type]
jax (https://github.com/google/jax)
- jax/experimental/mosaic/gpu/mma.py:199: error: Incompatible types in assignment (expression has type "ndarray[tuple[()], Any]", variable has type "list[Any]") [assignment]
+ jax/experimental/mosaic/gpu/mma.py:199: error: Incompatible types in assignment (expression has type "ndarray[tuple[()], dtype[Any]]", variable has type "list[Any]") [assignment]
+ jax/experimental/mosaic/gpu/tcgen05.py:1667: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int, int, int], dtype[Any]]", variable has type "ndarray[tuple[int, Any, int], dtype[Any]]") [assignment]
ibis (https://github.com/ibis-project/ibis)
- ibis/backends/clickhouse/__init__.py:517: error: Argument 1 to "Schema" has incompatible type "dict[Any, Any]"; expected "FrozenOrderedDict[str, DataType]" [arg-type]
+ ibis/backends/clickhouse/__init__.py:517: error: Argument 1 to "Schema" has incompatible type "dict[Any, DataType]"; expected "FrozenOrderedDict[str, DataType]" [arg-type]
- ibis/backends/impala/__init__.py:1203: error: Argument 1 to "Schema" has incompatible type "dict[Any, Any]"; expected "FrozenOrderedDict[str, DataType]" [arg-type]
+ ibis/backends/impala/__init__.py:1203: error: Argument 1 to "Schema" has incompatible type "dict[Any, DataType]"; expected "FrozenOrderedDict[str, DataType]" [arg-type]
- ibis/backends/singlestoredb/__init__.py:948: error: Argument 1 to "Schema" has incompatible type "dict[Any, Any]"; expected "FrozenOrderedDict[str, DataType]" [arg-type]
+ ibis/backends/singlestoredb/__init__.py:948: error: Argument 1 to "Schema" has incompatible type "dict[Any, DataType]"; expected "FrozenOrderedDict[str, DataType]" [arg-type]
imagehash (https://github.com/JohannesBuchner/imagehash)
+ imagehash/__init__.py:428: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[float64]]", variable has type "ndarray[tuple[int], dtype[signedinteger[_32Bit | _64Bit]]]") [assignment]
+ imagehash/__init__.py:432: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[float64]]", variable has type "ndarray[tuple[int], dtype[signedinteger[_32Bit | _64Bit]]]") [assignment]
static-frame (https://github.com/static-frame/static-frame)
- static_frame/core/index_hierarchy.py:1523: error: Returning Any from function declared to return "int" [no-any-return]
scipy-stubs (https://github.com/scipy/scipy-stubs)
+ tests/linalg/test__sketches.pyi:36: error: Unused "type: ignore" comment [unused-ignore]
+ tests/spatial/test__rigid_transform.pyi:46: error: Unused "type: ignore" comment [unused-ignore]
|
Member
Author
|
OK, I went through most of the new errors and they all seem real. In general, I think having such a ~neutral (some errors added, some are gone) primer result for a PR replacing |
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.
It is a common pattern (especially in numeric libraries) to have a fallback overload that has a relatively precise return type (i.e. not just
Anyorlist[Any]). We should try to find and use that overload if there is an ambiguity caused by an argument that containsAny.This will likely cause some new errors, but this should limit the fallout from #22011