Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
TYP: Adjust type hint of Norm.__call__ to return masked array#26434
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
xrefpydata/xarray#8030We were perhaps overly permissive in the return type, I'm pretty sure we always return Masked Array, so may as well say so, so that downstream can rely on that (which they already are, to be clear...)
You can also pass a scalar in and get a scalar out; should we |
Hmmmm... right you are... that ... complicates things as "scalar" is not a very easy thing to type hint even those from "ArrayLike" are actually insufficient... (and we do want to accept the non-scalar array likes (not just arrays...) perhaps @overloaddef__call__(self,value:np.ndarray,clip:bool|None= ...)->np.ma.MaskedArray: ...@overloaddef__call__(self,value:ArrayLike,clip:bool|None= ...)->ArrayLike: ... It's a little funky because the signatures are overlapping (whichcan be a problem to mypy... at least xarray is having a problem along those lines, but I think we may be saved by the return types being compatible, just one is more restricted...) This seems to help with xarray without causing us problems. Lists and other non-ndarray array likes (including scalars, to the extent that scalars are supported by type hints at all) will just not get the type narrowing that the output is a masked array, but those that care can easily do |
Uh oh!
There was an error while loading.Please reload this page.
…ns type consistent with superclass
PR summary
xrefpydata/xarray#8030
We were perhaps overly permissive in the return type, I'm pretty sure we always return Masked Array, so may as well say so, so that downstream can rely on that (which they already are, to be clear...)
PR checklist