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

gh-85602: Add docs for generating C function signatures #21673

Closed

Conversation

jameshcorbett
Copy link
Contributor

@jameshcorbett jameshcorbett commented Jul 29, 2020

Add documentation about how to generate nice function signatures (mostly for help and inspect) with C extension functions.

https://bugs.python.org/issue41430

Doc/extending/extending.rst Outdated Show resolved Hide resolved
Doc/extending/extending.rst Outdated Show resolved Hide resolved
Copy link

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

@picnixz picnixz changed the title bpo-41430 Add docs for generating C function signatures gh-85602: Add docs for generating C function signatures Dec 15, 2024
Comment on lines +348 to +357
The fourth entry is the function's docstring. Note the
``"system(command)\n--\n\n"`` at the beginning. Since C extension functions
take a fixed number of arguments---e.g. two for ``METH_VARARGS``---the Python
interpreter has no way of knowing the function's signature until the function
is called. However, by making the docstring start with something of the form
``"myfunc(arg1, arg2='my_default', arg3=17)\n--\n\n"``, the signature will be
constructed and the remainder of the docstring will be used as the function's
``__doc__`` attribute. This can be useful for generating nice messages with the
:func:`help` function or for getting the signature in object form with the
:func:`inspect.signature` function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The fourth entry is the function's docstring. Note the
``"system(command)\n--\n\n"`` at the beginning. Since C extension functions
take a fixed number of arguments---e.g. two for ``METH_VARARGS``---the Python
interpreter has no way of knowing the function's signature until the function
is called. However, by making the docstring start with something of the form
``"myfunc(arg1, arg2='my_default', arg3=17)\n--\n\n"``, the signature will be
constructed and the remainder of the docstring will be used as the function's
``__doc__`` attribute. This can be useful for generating nice messages with the
:func:`help` function or for getting the signature in object form with the
:func:`inspect.signature` function.
The fourth entry is the function's docstring. Note the
``"system(command)\n--\n\n"`` at the beginning. Since C extension functions
take a fixed number of arguments (for instance, two for ``METH_VARARGS``) the Python
interpreter has no way of knowing the function's signature until the function
is called. However, by making the docstring start with something of the form
``"myfunc(arg1, arg2='my_default', arg3=17)\n--\n\n"``, the signature will be
constructed and the remainder of the docstring will be used as the function's
``__doc__`` attribute. This is typically useful for generating nice messages with
:func:`help` or for getting the signature object with :func:`inspect.signature`.

@picnixz
Copy link
Contributor

picnixz commented Dec 15, 2024

Considering that we are not yet ready to support introspection like that on our side, we don't want to expose it to users. So I'll close this PR but we can revisit it once we are fine (though we have no idea how long it will take). Thanks for the work though!

@picnixz picnixz closed this Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

6 participants