Skip to content

TYP: fix np.shape assignability issue for python lists (#31171)#31182

Merged
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
jorenham:backport-31171
Apr 7, 2026
Merged

TYP: fix np.shape assignability issue for python lists (#31171)#31182
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
jorenham:backport-31171

Conversation

@jorenham
Copy link
Copy Markdown
Member

@jorenham jorenham commented Apr 7, 2026

Backport of #31171.


It was working fine when a list literal (e.g. [1, 2]) was passed, but some type-checkers would reject it when not passed directly, e.g. a: list[int] = [1, 2]; np.shape(a). This has the do with list having an invariant generic type parameter. The solution is to use a type variable, so that the item type can "vary" in the function scope.

AI Disclosure

N/A

@jorenham jorenham added this to the 2.4.5 release milestone Apr 7, 2026
@jorenham jorenham requested a review from charris April 7, 2026 16:12
@jorenham jorenham added 08 - Backport Used to tag backport PRs 41 - Static typing labels Apr 7, 2026
@charris charris merged commit 2ac5219 into numpy:maintenance/2.4.x Apr 7, 2026
12 checks passed
@charris
Copy link
Copy Markdown
Member

charris commented Apr 7, 2026

Thanks Joren.

@jorenham jorenham deleted the backport-31171 branch April 7, 2026 17:02
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.

2 participants