Skip to content

[3.11] gh-86457: Add docs for Argument Clinic @text_signature directive (#107747) #107799

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Doc/howto/clinic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1893,3 +1893,36 @@ blocks embedded in Python files look slightly different. They look like this:
#[python start generated code]*/
def foo(): pass
#/*[python checksum:...]*/


.. _clinic-howto-override-signature:

How to override the generated signature
---------------------------------------

You can use the ``@text_signature`` directive to override the default generated
signature in the docstring.
This can be useful for complex signatures that Argument Clinic cannot handle.
The ``@text_signature`` directive takes one argument:
the custom signature as a string.
The provided signature is copied verbatim to the generated docstring.

Example from :source:`Objects/codeobject.c`::

/*[clinic input]
@text_signature "($self, /, **changes)"
code.replace
*
co_argcount: int(c_default="self->co_argcount") = unchanged
co_posonlyargcount: int(c_default="self->co_posonlyargcount") = unchanged
# etc ...

Return a copy of the code object with new values for the specified fields.
[clinic start generated output]*/

The generated docstring ends up looking like this::

replace($self, /, **changes)
--

Return a copy of the code object with new values for the specified fields.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Argument Clinic now supports overriding automatically generated signature by
using directive ``@text_signature``.
using directive ``@text_signature``. See :ref:`clinic-howto-override-signature`.