BUG, TYP: Fix ma.core._frommethod function signatures
#30091
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This converts the
numpy.ma.core._frommethodmethod wrapper utility class to a function, and modifies the wrappedinspect.signatureto match that of the wrapper.Before:
After:
As you can see in the "before" output, the
aparameter was incorrectly reported as being the first one, which isn't the case. That's why I've labeled this as a bug.Before this, it wasn't possible to meaningfully annotate these
_frommethodfunctions, as stubtest did not recognize them as functions, but rather as instances of the_frommethodtype. But now that they're actual functions (i.e. instances ofFunctionType), we can annotate them like any other function, allowing us to use overloads and such.Note that there's also a similar situation for
np.ma.core._convert2ma. But I figured I'd first start with this one in case there are any objections, and otherwise address_convert2main a follow-up.Note that stubtest will not like this, so I'll now be working on updating the stubs. I'm not planning on touchingcore.pyanymore, so that part can already be reviewed. (I'll have to do a quick scipy-stubs release in the meantime though.)