-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
ENH: ufunc.__signature__
#30211
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?
ENH: ufunc.__signature__
#30211
Conversation
mhvk
left a comment
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.
Very nice! Main comment is about being explicit for gufuncs as well.
Also, as I was looking at https://numpy.org/doc/stable/reference/ufuncs.html to remind myself of the actual signatures, I saw that the text mentions __doc__ - do you want to mention __signature__ there as well? It does look like that list is complete, so might as well keep it like that!
Separately, currently np.add.reduce? just shows the docstring, so all fine from a user perspective. But does it work for introspection? If so, definitely for another PR, but I thought I'd mention it in part in case it has implications here, that really the __signature__ should somehow be attached to __call__ rather than the ufunc itself.
This comment was marked as resolved.
This comment was marked as resolved.
That even seems necessary, judging by the circleCI errors; I'll take of care of it.
That's initially what I had planned on doing. But that'd require a separate signature per ufunc instance, whereas for the other methods a one-size-fits-all signature is used. The C machinery surrounding |
Co-authored-by: Marten van Kerkwijk <[email protected]>
Co-authored-by: Marten van Kerkwijk <[email protected]>
f058983 to
eff475c
Compare
663b253 to
968636a
Compare
This adds a dynamic
__signature__attribute to the individual ufuncs, which gets used by introspection tools likeinspect.signature.tp_getattrois used in order to avoidufunc.__signature__from becoming a class attribute, which sphinx did not seem to like.Before, IPython showed something like this for
np.exp?:After this change, this is what it looks like:
The "call signature" refers to
np.ufunc.__call__.__text_signature__, which remains unchanged.In case of
divmod, the signature isGUFuncs include
**kwargs, because it's not known whether they have anaxisparameter: