Skip to content

Commit 6a0051f

Browse files
python/cpython#86457: Add docs for Argument Clinic @text_signature directive (python/cpython#107747)
Co-authored-by: Alex Waygood <[email protected]>
1 parent eec5f46 commit 6a0051f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Doc/howto/clinic.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,40 @@ blocks embedded in Python files look slightly different. They look like this:
19001900
#/*[python checksum:...]*/
19011901
19021902
1903+
.. _clinic-howto-override-signature:
1904+
1905+
How to override the generated signature
1906+
---------------------------------------
1907+
1908+
You can use the ``@text_signature`` directive to override the default generated
1909+
signature in the docstring.
1910+
This can be useful for complex signatures that Argument Clinic cannot handle.
1911+
The ``@text_signature`` directive takes one argument:
1912+
the custom signature as a string.
1913+
The provided signature is copied verbatim to the generated docstring.
1914+
1915+
Example from :source:`Objects/codeobject.c`::
1916+
1917+
/*[clinic input]
1918+
@text_signature "($self, /, **changes)"
1919+
code.replace
1920+
*
1921+
co_argcount: int(c_default="self->co_argcount") = unchanged
1922+
co_posonlyargcount: int(c_default="self->co_posonlyargcount") = unchanged
1923+
# etc ...
1924+
1925+
Return a copy of the code object with new values for the specified fields.
1926+
[clinic start generated output]*/
1927+
1928+
The generated docstring ends up looking like this::
1929+
1930+
Doc_STRVAR(code_replace__doc__,
1931+
"replace($self, /, **changes)\n"
1932+
"--\n"
1933+
"\n"
1934+
"Return a copy of the code object with new values for the specified fields.");
1935+
1936+
19031937
.. _clinic-howto-deprecate-positional:
19041938

19051939
How to deprecate passing parameters positionally

0 commit comments

Comments
 (0)