Skip to content

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
merged 2 commits into from
Jun 17, 2025

Conversation

charris
Copy link
Member

@charris charris commented Jun 17, 2025

Backports:

#29218

#29204

@charris charris added this to the 2.3.1 release milestone Jun 17, 2025
@charris charris added 08 - Backport Used to tag backport PRs 41 - Static typing labels Jun 17, 2025
@charris charris changed the base branch from main to maintenance/2.3.x June 17, 2025 20:58
@charris charris closed this Jun 17, 2025
@charris charris deleted the backport-29204-29218 branch June 17, 2025 21:01
@charris charris restored the backport-29204-29218 branch June 17, 2025 21:01
@charris charris reopened this Jun 17, 2025
@jorenham

This comment was marked as outdated.

Copy link

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]

@charris charris merged commit 2f564ef into numpy:maintenance/2.3.x Jun 17, 2025
74 of 75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
08 - Backport Used to tag backport PRs 41 - Static typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TYP: incorrect type inference for iteration elements? (numpy 2.3.0) TYP: typehints for __array__
2 participants