-
Notifications
You must be signed in to change notification settings - Fork 140
Description
The CPython has no "official" way to specify signatures in extension modules. I did (unsuccessful) attempt to address this issue in https://discuss.python.org/t/43914.
One approach (e.g. sphinx-doc) is using the PEP 7-style docstrings:
The first line of each function docstring should be a “signature line” that gives a brief synopsis of the arguments and return value.
Another one, used by CPython's builtin's and stdlib - fill the __text_signature__ attribute for callables like:
function_name(arguments)
--
actual docstring, *without* PEP 7 "signature line".
The function_name(arguments) line (with some specific syntax for the first function argument, you shouldn't care about) literally goes to the __text_signature__ attribute. While it's not a public API, hardly this interface will disappear soon. Thus, some alternative Python implementation sometimes offer support for this way (though, incomplete, see e.g. pypy/pypy#5368). Maybe GraalPy can too?
If no, maybe you could cut off all leading text from docstrings, before and including of the \n--\n\n separator? So, it will not appear in the help() output as now (using the python-gmp package as an example):
Python 3.12.8 (Thu Oct 09 17:26:36 UTC 2025)
[Graal, Oracle GraalVM, Java 25.0.1 (amd64)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gmp import isqrt
>>> print(isqrt.__doc__)
isqrt($module, n, /)
--
Return the integer part of the square root of n.
>>> help(isqrt)
Help on built-in function isqrt in module gmp:
isqrt(...)
isqrt($module, n, /)
--
Return the integer part of the square root of n.