-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
TYP: Backport typing fixes #29222
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
Merged
charris
merged 2 commits into
numpy:maintenance/2.3.x
from
charris:backport-29204-29218
Jun 17, 2025
Merged
TYP: Backport typing fixes #29222
charris
merged 2 commits into
numpy:maintenance/2.3.x
from
charris:backport-29204-29218
Jun 17, 2025
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
This comment was marked as outdated.
This comment was marked as outdated.
Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code: rclip (https://github.com/yurijmikhalevich/rclip)
- rclip/model.py:218: error: Argument "key" to "sorted" has incompatible type "Callable[[tuple[float64, int]], float64]"; expected "Callable[[tuple[float64, int]], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type]
- rclip/model.py:218: error: Incompatible return value type (got "float64", expected "SupportsDunderLT[Any] | SupportsDunderGT[Any]") [return-value]
- rclip/model.py:220: error: Incompatible return value type (got "list[tuple[float64, int]]", expected "list[tuple[float, int]]") [return-value]
- rclip/model.py:220: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
- rclip/model.py:220: note: Consider using "Sequence" instead, which is covariant
- rclip/model.py:220: note: Perhaps you need a type annotation for "sorted_similarities"? Suggestion: "list[tuple[float, int]]"
xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_namedarray.py:212: error: Argument 2 to "NamedArray" has incompatible type "ndarray[tuple[Any, ...], dtype[signedinteger[_64Bit]]]"; expected "_arrayfunction[Any, Never] | _arrayapi[Any, Never]" [arg-type]
+ xarray/tests/test_namedarray.py: note: In member "test_duck_array_class" of class "TestNamedArray":
+ xarray/tests/test_namedarray.py:373: error: Argument 1 to "check_duck_array_typevar" has incompatible type "ndarray[tuple[Any, ...], dtype[signedinteger[_64Bit]]]"; expected "_arrayfunction[Any, Never] | _arrayapi[Any, Never]" [arg-type]
+ xarray/tests/test_namedarray.py:377: error: Argument 1 to "check_duck_array_typevar" has incompatible type "MaskedArray[Any, dtype[signedinteger[_64Bit]]]"; expected "_arrayfunction[Any, Never] | _arrayapi[Any, Never]" [arg-type]
+ xarray/tests/test_namedarray.py: note: In class "TestNamedArray":
+ xarray/tests/test_namedarray.py: note: In member "test_warn_on_repeated_dimension_names" of class "TestNamedArray":
+ xarray/tests/test_namedarray.py:592: error: Argument 2 to "NamedArray" has incompatible type "ndarray[tuple[int, int], dtype[signedinteger[Any]]]"; expected "_arrayfunction[Any, Never] | _arrayapi[Any, Never]" [arg-type]
jax (https://github.com/google/jax)
+ jax/_src/pallas/hlo_interpreter.py:93: error: Unused "type: ignore" comment [unused-ignore]
static-frame (https://github.com/static-frame/static-frame)
- static_frame/core/loc_map.py:428: error: Incompatible types in assignment (expression has type "unsignedinteger[_64Bit]", variable has type "ndarray[tuple[Any, ...], dtype[unsignedinteger[_64Bit]]]") [assignment]
+ static_frame/core/container_util.py:1339: error: Unused "type: ignore" comment [unused-ignore]
dedupe (https://github.com/dedupeio/dedupe)
- dedupe/clustering.py:59: error: Incompatible types in assignment (expression has type "signedinteger[_64Bit]", variable has type "int") [assignment]
- dedupe/labeler.py:199: error: Generator has incompatible item type "tuple[int | str, int | str]"; expected "tuple[int, int] | tuple[str, str]" [misc]
- dedupe/convenience.py:99: error: "signedinteger[_64Bit]" object is not iterable [misc]
- dedupe/convenience.py:99: error: Cannot determine type of "p" [has-type]
- dedupe/convenience.py:99: error: Cannot determine type of "q" [has-type]
hydpy (https://github.com/hydpy-dev/hydpy)
- hydpy/core/objecttools.py:955: error: Argument 1 to "repr_values" has incompatible type "Sequence[object] | ndarray[tuple[Any, ...], dtype[generic[Any]]] | generic[Any]"; expected "Sequence[object] | ndarray[tuple[Any, ...], dtype[generic[Any]]]" [arg-type]
- hydpy/core/netcdftools.py:489: error: Argument 1 to "join" of "bytes" has incompatible type "bytes_"; expected "Iterable[Buffer]" [arg-type]
- hydpy/core/netcdftools.py:489: note: Following member(s) of "bytes_" have conflicts:
- hydpy/core/netcdftools.py:489: note: Expected:
- hydpy/core/netcdftools.py:489: note: def __iter__(self) -> Iterator[Buffer]
- hydpy/core/netcdftools.py:489: note: Got:
- hydpy/core/netcdftools.py:489: note: def __iter__(self) -> Iterator[int]
- hydpy/core/netcdftools.py:489: note: Expected:
- hydpy/core/netcdftools.py:489: note: def __iter__(self) -> Iterator[Buffer]
- hydpy/core/netcdftools.py:489: note: Got:
- hydpy/core/netcdftools.py:489: note: def __iter__(self) -> Iterator[int]
- hydpy/core/netcdftools.py:489: note: Expected:
- hydpy/core/netcdftools.py:489: note: def __iter__(self) -> Iterator[Buffer]
- hydpy/core/netcdftools.py:489: note: Got:
- hydpy/core/netcdftools.py:489: note: def __iter__(self) -> Iterator[int]
- hydpy/core/itemtools.py:951: error: Argument 2 to "update_variable" of "ChangeItem" has incompatible type "float64"; expected "ndarray[tuple[Any, ...], dtype[float64]]" [arg-type]
- hydpy/core/itemtools.py:954: error: Argument 2 to "update_variable" of "ChangeItem" has incompatible type "float64"; expected "ndarray[tuple[Any, ...], dtype[float64]]" [arg-type]
- hydpy/auxs/ppolytools.py:253: error: Value of type variable "_AnyShapeT" of "__call__" of "_ConstructorEmpty" cannot be "tuple[int, signedinteger[_64Bit]]" [type-var]
- hydpy/auxs/ppolytools.py:253: error: Value of type variable "SupportsRichComparisonT" of "max" cannot be "signedinteger[_64Bit]" [type-var]
- hydpy/auxs/ppolytools.py:661: error: Value of type "float64" is not indexable [index]
spark (https://github.com/apache/spark)
- python/pyspark/sql/streaming/benchmark/utils.py:26: error: Incompatible types in string interpolation (expression has type "floating[Any]", placeholder has type "int | float") [str-format]
scipy (https://github.com/scipy/scipy)
- scipy/spatial/tests/test_spherical_voronoi.py:194: error: Value of type variable "SupportsRichComparisonT" of "sorted" cannot be "floating[Any]" [type-var]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/array_algos/quantile.py:199: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/sorting.py:479: error: Unused "type: ignore" comment [unused-ignore]
- pandas/tseries/frequencies.py:274: error: List comprehension has incompatible type List[floating[_64Bit]]; expected List[int] [misc]
- pandas/tseries/frequencies.py:279: error: List comprehension has incompatible type List[floating[_64Bit]]; expected List[int] [misc]
- pandas/core/arrays/datetimelike.py:1293: error: No overload variant of "__mul__" of "BaseOffset" matches argument type "signedinteger[_64Bit]" [operator]
- pandas/core/arrays/datetimelike.py:1293: note: Possible overload variants:
- pandas/core/arrays/datetimelike.py:1293: note: def __mul__(self, ndarray[tuple[Any, ...], dtype[Any]], /) -> ndarray[tuple[Any, ...], dtype[Any]]
- pandas/core/arrays/datetimelike.py:1293: note: def __mul__(self, int, /) -> BaseOffset
- pandas/io/stata.py:1448: error: Invalid index type "unsignedinteger[_8Bit]" for "dict[int, int]"; expected type "int" [index]
- pandas/io/stata.py:1450: error: Argument 1 to "append" of "list" has incompatible type "unsignedinteger[_8Bit]"; expected "int" [arg-type]
+ pandas/io/parsers/python_parser.py:1471: error: Unused "type: ignore" comment [unused-ignore]
- pandas/core/internals/managers.py:1527: error: "BlockPlacement" has no attribute "increment_above" [attr-defined]
+ pandas/core/internals/construction.py:637: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/internals/blocks.py:2101: error: Unused "type: ignore" comment [unused-ignore]
- pandas/io/formats/style_render.py:1243: error: Invalid index type "tuple[signedinteger[_32Bit | _64Bit], signedinteger[_32Bit | _64Bit]]" for "defaultdict[tuple[int, int], Callable[[Any], str]]"; expected type "tuple[int, int]" [index]
|
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.
Backports:
#29218
TYP: Workaround for a mypy issue in ndarray.iter
Closes TYP: incorrect type inference for iteration elements? (numpy 2.3.0) #29214
The workaround I had in mind was also bugged, so I suppose that'd make it a workaroundaround.
And just like that term, this workaroundaround itself also looks pretty absurd.
#29204
closes TYP: typehints for __array__ #29203