It was EB decision that sphinx docs should include correct signatures: Function signatures should use slash/star as needed by nedbat · Pull Request #1344 · python/devguide · GitHub (see also discussion thread: Editorial Board decisions) and this is documented in the Python Developer’s Guide.
Is this for new code only or EB has some plans to change existing docs?
The current state looks horrible. Take e.g. the builtin functions page. Already here we have signatures with slashes (e.g. bool, int or complex) and without (e.g. any or bin). On the Built-in Types page some above signatures are documented with funny square bracket syntax (which actually not explained somewhere). See the range() as an example and CPython issue: Built-in function `range` params discrepancy across versions · Issue #125897 · python/cpython · GitHub.
It was argued (see this as an example), that omitting some required markers in the function signature — makes the docs much more usable for readers, especially newcomers. But I believe it might be wrong sometimes. Take current range(start, stop, step=1)
signature from the builtin functions page. Does step=1
means (1) just that the range has a default value for the third argument, or (2) it accepts a keyword argument step
? For range
— (1) is true, but not (2). But nearby we have e.g. the round(number, ndigits=None)
with same syntax, that does accept keyword argument ndigits
((1) and (2) meaning).
We can start adding required syntax markers to docs (again, see Doc: Make functions.html readable again. by JulienPalard · Pull Request #99476 · python/cpython · GitHub), but maybe there is a better way. Why not add support for keyword arguments in builtin functions? Then “simple” signatures (like range(start, stop, step=1)
) — will be correct. Also this will lower mental barrier between C-coded functions and pure-Python code (where per-default keyword arguments are allowed). IIRC, PyPy’s builtins, implemented in RPython — allow keyword arguments too.
I would guess, before inventing the Argument Clinic this was a complex task and we had positional-only arguments for builtins as a historical artifact of this. But now it’s more or less trivial.
Possible issue is some overhead for argument processing. I tested conversion for cmath’s functions in my pr and got ~5% performance penalty:
In the main:
$ ./python -m timeit -r11 -s 'from cmath import sin;z=1j' 'sin(z)'
1000000 loops, best of 11: 312 nsec per loop
With patch:
$ ./python -m timeit -r11 -s 'from cmath import sin;z=1j' 'sin(z)'
1000000 loops, best of 11: 330 nsec per loop
Maybe it’s not too high price for consistent, readable and accurate docs. I would expect this could be more or less true for most of builtins/stdlib.