8000 TYP: type hint ``numpy.polynomial`` by jorenham · Pull Request #26897 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: type hint numpy.polynomial #26897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 23, 2024
Merged

Conversation

jorenham
Copy link
Member
@jorenham jorenham commented Jul 10, 2024

The underrated numpy.polynomial gem deserves to have proper type annotations; so here's my attempt 😄.

Previously, there only were blank (and outdated) stubgen stubs.
This PR replaces them with hand-crafted and type-tested ones.

I did my best to avoid making the stubs too difficult to read / maintain.
For this reason, I have made the annotations slightly less precise than was possible, because it would harm the readability too much, by e.g. by requiring 30 overloads.

For the new internal type-aliases and protocols, I attempted to stay close to the numpy naming-scheme. For example _SeriesLikeComplex_co represents a 1-d array-like, limited to have a number, bool, or object scalar type.

@jorenham jorenham marked this pull request as draft July 10, 2024 03:36
@jorenham jorenham force-pushed the polynomial-typing branch 2 times, most recently from 0ce29c8 to d0945bd Compare July 15, 2024 21:15
@jorenham jorenham marked this pull request as ready for review July 16, 2024 23:25
@charris charris changed the title TYP: type hint numpy.polynomial TYP: type hint numpy.polynomial Jul 18, 2024
Copy link
Member
@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks a lot @jorenham!

This PR is too large for me (or anyone else at this moment I think) to review line by line. I do want to get this in for 2.1.0 though, since it's a lot of work and there's a lot of user demand for improved type annotations. So I reviewed by spot checking some of the annotations themselves, and looking at the tests. I didn't find any obvious problems, and this is clearly a significant improvement, so I'll go ahead and merge it. I'm confident it's in good shape overall, and in case we get reports about issues later they can be addressed then.

For this reason, I have made the annotations slightly less precise than was possible, because it would harm the readability too much, by e.g. by requiring 30 overloads.

Good call - I think you struck the right balance here.

@rgommers rgommers merged commit 8be0e74 into numpy:main Jul 23, 2024
68 checks passed
@rgommers rgommers added this to the 2.1.0 release milestone Jul 23, 2024
@jorenham jorenham deleted the polynomial-typing branch July 23, 2024 19:09
jorenham added a commit to jorenham/numpy that referenced this pull request Aug 10, 2024
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
0