-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
gh-85602: Add docs for generating C function signatures #21673
Conversation
The following commit authors need to sign the Contributor License Agreement: |
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. |
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.
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`. |
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! |
Add documentation about how to generate nice function signatures (mostly for
help
andinspect
) with C extension functions.https://bugs.python.org/issue41430