-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
numpy/ma/core.pyi
Outdated
def power(a, b, third=...): ... | ||
def argsort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ... | ||
def power(a, b, third=None): ... | ||
def argsort(a, axis=..., kind=None, order=None, endwith=True, fill_value=None, *, stable=...): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the libcst codemod support keyword-only parameters?
def argsort(a, axis=..., kind=None, order=None, endwith=True, fill_value=None, *, stable=...): ... | |
def argsort(a, axis=..., kind=None, order=None, endwith=True, fill_value=None, *, stable=None): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, fixed, thanks! yangdanny97/docs2types#6
def transpose(a, axes=...): ... | ||
def reshape(a, new_shape, order=...): ... | ||
def transpose(a, axes=None): ... | ||
def reshape(a, new_shape, order='C'): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that there are some existing '
quotes here and there, but "
is used way more often. I'm kinda surprised that ruff accepts this though 🤔
def reshape(a, new_shape, order='C'): ... | |
def reshape(a, new_shape, order="C"): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really have a preference, but I think if it's a project preference then it should be automated - I've opened #29548 for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then a ruff check --fix
should now fix this :)
def where(condition, x=..., y=...): ... | ||
def choose(indices, choices, out=..., mode=...): ... | ||
def round_(a, decimals=..., out=...): ... | ||
def choose(indices, choices, out=None, mode='raise'): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def choose(indices, choices, out=None, mode='raise'): ... | |
def choose(indices, choices, out=None, mode="raise"): ... |
def correlate(a, v, mode='valid', propagate_mask=True): ... | ||
def convolve(a, v, mode='full', propagate_mask=True): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def correlate(a, v, mode='valid', propagate_mask=True): ... | |
def convolve(a, v, mode='full', propagate_mask=True): ... | |
def correlate(a, v, mode="valid", propagate_mask=True): ... | |
def convolve(a, v, mode="full", propagate_mask=True): ... |
numpy/ma/extras.pyi
Outdated
@@ -55,7 +55,7 @@ __all__ = [ | |||
"vstack", | |||
] | |||
|
|||
def count_masked(arr, axis=...): ... | |||
def count_masked(arr, axis=None): ... | |||
def masked_all(shape, dtype=...): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ruff PYI014
wouldn't accept this I think, which is pretty arbitrary if you ask me.
def masked_all(shape, dtype=...): ... | |
def masked_all(shape, dtype=float): ... # noqa: PYI014 |
commentchar='#', | ||
missingchar='', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commentchar='#', | |
missingchar='', | |
commentchar="#", | |
missingchar="", |
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:
= ...
...
inThe ones in this PR, I checked manually, and they look correct to me