Skip to content

TYP: Type default values in stubs in numpy/ma #29531

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 11 commits into from
Aug 18, 2025

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Aug 7, 2025

Making some progress towards #28428

Similar PR in pandas: pandas-dev/pandas-stubs#1293

I've done this based on work started in https://gist.github.com/yangdanny97/170f82ee5389584f8b6292bc4ea9c24d, we're looking at open-sourcing a reusable tool to do this automatically where possible:

  • if a stub file uses = ...
  • and the corresponding defintion has a simple default
  • then fill the ... in

The ones in this PR, I checked manually, and they look correct to me

@jorenham jorenham added the component: numpy.ma masked arrays label Aug 8, 2025
@jorenham jorenham self-requested a review August 11, 2025 18:50
Copy link
Member

@jorenham jorenham left a comment

Choose a reason for hiding this comment

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

I like the libcst approach, and the ones I checked seem to all be correct.

Technically speaking, this has little to do with static typing, but can be very helpful for IDE introspection, which is also one of the main advantages of annotations, so I suppose it's fine to keep the TYP: label.

For most defaults I can see that they can be useful. But in some cases, like out=None, I'm not if the defaults are actually helpful. Because without annotations, just having out=None doesn't give you any additional information about how it can be used. It could even be a bit confusing this way if some parameters use =None and others =np._NoValue (i.e. =...), especially if you consider that the documentation of _NoValue often incorrectly says it defaults to None. That could be confusing because it appears to be inconsistent.

Anyway, it probably doesn't matter much, so I'm fine with keeping those =None. Removing them now would mean we'd have to add them back in again once we add the annotations.

@jorenham jorenham merged commit e7d3a29 into numpy:main Aug 18, 2025
77 of 79 checks passed
@jorenham
Copy link
Member

Thanks

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