Skip to content

TYP: poly1d shape-typing - #32750

Merged
charris merged 1 commit into
numpy:mainfrom
jorenham:typing/poly1d/shape-typing
Sep 22, 2026
Merged

charris merged 1 commit into
numpy:mainfrom
jorenham:typing/poly1d/shape-typing

Conversation

@jorenham

Copy link
Copy Markdown
Member

The array types of np.poly1d are now narrowed to have 1d shape-type, because suprisingly, poly1d is 1d. There's one exception though, and that's when 0d or >1d array-likes are passed as val to np.poly1d.__call__, in which case the shape is preserved. So this also adds overloads to __call__ so that arrays with known shape-type return an exact shape-type, and bare scalar-likes, 1d- and 2d array-like sequences also return a rank-2 array.

I've used Incomplete instead of Any for scalar-types (which Incomplete simply aliases) because it's possible, and even feasible, to make those exact. Doing so would require turning poly1d into a generic type though, so that's out of scope here, and probably needs to be discussed a bit to see if we actually want to do that (seeing as poly1d is considered legacy-ish functionality). So I guess I'll put it on the agenda for tomorrow's community meeting.


Pair programmed with AI.

@jorenham jorenham added this to the 2.6.0 Release milestone Sep 22, 2026
@charris
charris merged commit 45af74b into numpy:main Sep 22, 2026
16 checks passed
@charris

charris commented Sep 22, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

@jorenham
jorenham deleted the typing/poly1d/shape-typing branch September 22, 2026 18:10
Riaz1729 pushed a commit to Riaz1729/numpy that referenced this pull request Sep 23, 2026
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