Skip to content

TYP: transpose and matrix_transpose improved shape-typing - #32271

Merged
charris merged 2 commits into
numpy:mainfrom
jorenham:typing/transpose/improved-shape-typing
Aug 12, 2026
Merged

charris merged 2 commits into
numpy:mainfrom
jorenham:typing/transpose/improved-shape-typing

Conversation

@jorenham

@jorenham jorenham commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

This adds overloads to the transpose functions for shaped-typed results of (nesdted) sequences of Python builtins.

The transpose and matrix_transpose overloads are isomorphic, and the functions clearly related, hence this two-for-one.


Fun fact: according to the AI shape-typing audit (gist), matrix_transpose is the least popular non-legacy NumPy function in the main namespace.


Fully written by me, audited as kinda-high-value shape-typing improvement by AI (see gist).

@jorenham jorenham added this to the 2.6.0 Release milestone Aug 12, 2026
@github-actions

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:

optuna (https://github.com/optuna/optuna)
  ./optuna/study/_multi_objective.py:182: error: INTERNAL ERROR -- Please try using mypy master on GitHub:

@charris
charris merged commit 849f84d into numpy:main Aug 12, 2026
15 checks passed
@charris

charris commented Aug 12, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

@jorenham
jorenham deleted the typing/transpose/improved-shape-typing branch August 12, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants