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: ``tile`` shape-typing by jorenham · Pull Request #32249 · numpy/numpy

Conversation

@jorenham

@jorenham jorenham commented Aug 11, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This adds a bunch of overloads to tile so that the returned ndarray has an accurate shape-type for the most common cases (verified using code search).


Fully written by me, pre-reviewed and audited by AI (see https://gist.github.com/jorenham/36c78602a7ca866ddb2a917de48ccdd0).

Sorry, something went wrong.

Uh oh!

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

All reactions
@jorenham
TYP: tile shape-typing
61a778f
@jorenham jorenham added the 41 - Static typing label Aug 11, 2026
@jorenham jorenham added this to the 2.6.0 Release milestone Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026

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:

colour (https://github.com/colour-science/colour)
- colour/io/luts/lut.py:1419: error: Argument 1 to "tile" has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]]"  [arg-type]
+ colour/io/luts/lut.py:1419: error: Argument 1 to "tile" has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None"; expected "Sequence[complex | str | bytes | generic[Any]] | complex | str | bytes | generic[Any]"  [arg-type]
- colour/io/luts/lut.py:1419: error: Argument 1 to "tile" has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None"; expected "_SupportsArray[dtype[signedinteger[_8Bit] | signedinteger[_16Bit] | signedinteger[_32Bit] | signedinteger[_64Bit] | unsignedinteger[_8Bit] | unsignedinteger[_16Bit] | unsignedinteger[_32Bit] | unsignedinteger[_64Bit] | Any]] | _NestedSequence[_SupportsArray[dtype[signedinteger[_8Bit] | signedinteger[_16Bit] | signedinteger[_32Bit] | signedinteger[_64Bit] | unsignedinteger[_8Bit] | unsignedinteger[_16Bit] | unsignedinteger[_32Bit] | unsignedinteger[_64Bit] | Any]]]"  [arg-type]
+ 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: note: Possible overload variants:
+ colour/io/luts/lut.py:1433: note:     def [ShapeT: tuple[int, ...], DTypeT: dtype[Any]] pad(array: ndarray[ShapeT, DTypeT], pad_width: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | dict[int, int] | dict[int, tuple[int, int]] | dict[int, int | tuple[int, int]], mode: Literal['constant', 'edge', 'linear_ramp', 'maximum', 'mean', 'median', 'minimum', 'reflect', 'symmetric', 'wrap', 'empty'] = ..., *, stat_length: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | None = ..., constant_values: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = ..., end_values: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = ..., reflect_type: Literal['odd', 'even'] = ...) -> ndarray[ShapeT, DTypeT]
+ colour/io/luts/lut.py:1433: note:     def [ScalarT: generic[Any]] pad(array: _SupportsArray[dtype[ScalarT]] | _NestedSequence[_SupportsArray[dtype[ScalarT]]], pad_width: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | dict[int, int] | dict[int, tuple[int, int]] | dict[int, int | tuple[int, int]], mode: Literal['constant', 'edge', 'linear_ramp', 'maximum', 'mean', 'median', 'minimum', 'reflect', 'symmetric', 'wrap', 'empty'] = ..., *, stat_length: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | None = ..., constant_values: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = ..., end_values: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = ..., reflect_type: Literal['odd', 'even'] = ...) -> ndarray[tuple[Any, ...], dtype[ScalarT]]
+ colour/io/luts/lut.py:1433: note:     def pad(array: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], pad_width: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | dict[int, int] | dict[int, tuple[int, int]] | dict[int, int | tuple[int, int]], mode: Literal['constant', 'edge', 'linear_ramp', 'maximum', 'mean', 'median', 'minimum', 'reflect', 'symmetric', 'wrap', 'empty'] = ..., *, stat_length: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | None = ..., constant_values: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = ..., end_values: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = ..., reflect_type: Literal['odd', 'even'] = ...) -> ndarray[tuple[Any, ...], dtype[Any]]
+ colour/io/luts/lut.py:1433: note:     def [ShapeT: tuple[int, ...], DTypeT: dtype[Any]] pad(array: ndarray[ShapeT, DTypeT], pad_width: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | dict[int, int] | dict[int, tuple[int, int]] | dict[int, int | tuple[int, int]], mode: _ModeFunc, **kwargs: Any) -> ndarray[ShapeT, DTypeT]
+ colour/io/luts/lut.py:1433: note:     def [ScalarT: generic[Any]] pad(array: _SupportsArray[dtype[ScalarT]] | _NestedSequence[_SupportsArray[dtype[ScalarT]]], pad_width: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | dict[int, int] | dict[int, tuple[int, int]] | dict[int, int | tuple[int, int]], mode: _ModeFunc, **kwargs: Any) -> ndarray[tuple[Any, ...], dtype[ScalarT]]
+ colour/io/luts/lut.py:1433: note:     def pad(array: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], pad_width: _SupportsArray[dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[integer[Any]]]] | int | _NestedSequence[int] | dict[int, int] | dict[int, tuple[int, int]] | dict[int, int | tuple[int, int]], mode: _ModeFunc, **kwargs: Any) -> ndarray[tuple[Any, ...], dtype[Any]]
- colour/io/luts/lut.py:1955: error: Argument 1 to "tile" has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None"; expected "_SupportsArray[dtype[signedinteger[_8Bit] | signedinteger[_16Bit] | signedinteger[_32Bit] | signedinteger[_64Bit] | unsignedinteger[_8Bit] | unsignedinteger[_16Bit] | unsignedinteger[_32Bit] | unsignedinteger[_64Bit]]] | _NestedSequence[_SupportsArray[dtype[signedinteger[_8Bit] | signedinteger[_16Bit] | signedinteger[_32Bit] | signedinteger[_64Bit] | unsignedinteger[_8Bit] | unsignedinteger[_16Bit] | unsignedinteger[_32Bit] | unsignedinteger[_64Bit]]]]"  [arg-type]
+ colour/io/luts/lut.py:1955: error: Argument 1 to "tile" has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None"; expected "Sequence[complex | str | bytes | generic[Any]] | complex | str | bytes | generic[Any]"  [arg-type]
+ colour/utilities/tests/test_array.py:1974: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[signedinteger[_32Bit | _64Bit]]]", variable has type "ndarray[tuple[int], dtype[signedinteger[_32Bit | _64Bit]]]")  [assignment]
- colour/temperature/tests/test_robertson1968.py:171: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/temperature/tests/test_robertson1968.py:171: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[Any]]", variable has type "float")  [assignment]
- colour/temperature/tests/test_robertson1968.py:230: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]
+ colour/temperature/tests/test_robertson1968.py:230: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[Any]]", variable has type "int")  [assignment]
- colour/temperature/tests/test_planck1900.py:143: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]
+ colour/temperature/tests/test_planck1900.py:143: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "int")  [assignment]
- colour/temperature/tests/test_mccamy1992.py:140: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/temperature/tests/test_mccamy1992.py:140: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/temperature/tests/test_krystek1985.py:142: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]
+ colour/temperature/tests/test_krystek1985.py:142: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "int")  [assignment]
- colour/temperature/tests/test_kang2002.py:143: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]
+ colour/temperature/tests/test_kang2002.py:143: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "int")  [assignment]
- colour/temperature/tests/test_hernandez1999.py:140: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/temperature/tests/test_hernandez1999.py:140: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/temperature/tests/test_cie_d.py:137: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]
+ colour/temperature/tests/test_cie_d.py:137: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "int")  [assignment]
- colour/phenomena/tests/test_tmm.py:82: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_tmm.py:82: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:521: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:521: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:596: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:596: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:671: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:671: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:758: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:758: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:829: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:829: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:893: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:893: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:944: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:944: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:992: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:992: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:1056: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:1056: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:1141: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:1141: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:1200: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:1200: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "int")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:1265: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:1265: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "int")  [assignment]
- colour/phenomena/tests/test_rayleigh.py:1329: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "float")  [assignment]
+ colour/phenomena/tests/test_rayleigh.py:1329: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
- colour/phenomena/tests/test_interference.py:72: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]
+ colour/phenomena/tests/test_interference.py:72: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "int")  [assignment]
- colour/phenomena/tests/test_interference.py:149: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "int")  [assignment]

... (truncated 491 lines) ...

optuna (https://github.com/optuna/optuna)
  ./optuna/study/_multi_objective.py:182: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
jorenham reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@jorenham

jorenham commented Aug 11, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

I went over the full colour mypy_primer diff (which is 500+ lines; they really seem to like np.tile :P) and "cancelled out" the errors that only changed in message:

+ 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/utilities/tests/test_array.py:1974: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[signedinteger[_32Bit | _64Bit]]]", variable has type "ndarray[tuple[int], dtype[signedinteger[_32Bit | _64Bit]]]")  [assignment]
+ colour/models/rgb/transfer_functions/tests/test_linear.py:51: error: Incompatible types in assignment (expression has type "ndarray[tuple[int], dtype[Any]]", variable has type "float")  [assignment]
  • colour/io/luts/lut.py:1433: I'm not entirely sure what exactly the problem is because there's a lot going on here. But what I do known is that this is not related to np.tile. It instead seems to either be caused by an overly broad return type of np.max, an overly restrictive np.pad parameter type, or a fluke in mypy's inference algorithm. Either way, it's not a regression in tile.
  • colour/utilities/tests/test_array.py:1974: re-assignment to a which already had a different, incompatible, shape-type. This is something that can already be resolved by configuring mypy appropriately (allowing redefinitions).
  • colour/models/rgb/transfer_functions/tests/test_linear.py:51: Same reassignment issue as above -- nothing we can help

TLDR; nothing here points to a regression in np.tile

All reactions

Sorry, something went wrong.

Uh oh!

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

@charris
charris merged commit a23509e into numpy:main Aug 11, 2026
15 checks passed

Uh oh!

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

@charris

charris commented Aug 11, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

jorenham reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@jorenham
jorenham deleted the typing/tile/shape-typing branch August 11, 2026 22:19
@jorenham jorenham mentioned this pull request Sep 30, 2026
TYP/DOC: release notes for the main numpy namespace shape-typing improvements #32835
Merged
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

41 - Static typing

Projects

None yet

Milestone

2.6.0 Release

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

2 participants

@jorenham @charris
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.