Skip to content
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

Show signature for binding=False cython functions #39279

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

user202729
Copy link
Contributor

@user202729 user202729 commented Jan 4, 2025

Fixes #26254 , without binding=True. (That is, this shows the signature correctly in function? for certain functions compiled in Cython.)

Before:

sage: prime_pi??
Type:           PrimePi
String form:    prime_pi
File:           /usr/lib/python3.13/site-packages/sage/functions/prime_pi.pyx
Source:        
cdef class PrimePi(BuiltinFunction):
[...]

After:

sage: prime_pi??
Signature:      prime_pi()
Call signature: prime_pi(self, coerce=True, hold=False, *args)
Type:           PrimePi
String form:    prime_pi
File:           ~/sage/src/sage/functions/prime_pi.pyx
Source:        
cdef class PrimePi(BuiltinFunction):

Even if we ultimately decide to set binding=True, this would probably still be desirable, in case some other library chooses to use binding=False, embedsignature=True.

Note: there's an alternative of implementing this into IPython, see ipython/ipython#14639

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

sage: def f(x, y, z=1, t=2, *args, **keywords):
....: pass
sage: sage_signature(f)
<Signature (x, y, z=1, t=2, *args, **keywords)>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

examples mostly copied from sage_getargspec, modified accordingly.

Copy link

github-actions bot commented Jan 5, 2025

Documentation preview for this PR (built with commit d641e4b; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@tobiasdiez
Copy link
Contributor

Note: there's an alternative of implementing this into IPython

Would this be much work? Since this seems to be 'just' a cython-specific problem, and nothing intrinsically related to sage, I would prefer if this could be fixed upstream in IPython (in fact, I hope that most of the special Cython handling in sage.inspect could be moved to upstream, either IPython or Python)

@user202729
Copy link
Contributor Author

Might be worth trying, let's see.

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.

Use Cython directive binding=True to get signatures for cython methods
2 participants