GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TYP: Backport typing fixes by charris · Pull Request #29222 · numpy/numpy

Conversation

@charris

@charris charris commented Jun 17, 2025

Copy link
Copy Markdown
Member

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

  • TYP: fix ndarray.array annotation for copy
    closes TYP: typehints for __array__ #29203

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jorenham added 2 commits June 17, 2025 13:44
@jorenham @charris
TYP: fix ndarray.__array__ annotation for copy (numpy#29204)
e6e0004
@jorenham @charris
TYP: Workaround for a mypy issue in ndarray.__iter__ (numpy#29218)
6fb2632
@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.

Sign in to view
@github-actions

github-actions Bot commented Jun 17, 2025

Copy link
Copy Markdown

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]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charris
charris merged commit 2f564ef into numpy:maintenance/2.3.x Jun 17, 2025
@JstnMcBrd JstnMcBrd mentioned this pull request Jun 18, 2025
Bump numpy from 2.2.6 to 2.3.0 JstnMcBrd/ray-tracer#33
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

08 - Backport Used to tag backport PRs 41 - Static typing

Projects

None yet

Milestone

2.3.1 release

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__

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@charris @jorenham
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.