Skip to content

Commit 44891a4

Browse files
committed
Update the 'Python Signatures' section
1 parent 4d4123b commit 44891a4

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

doc/usage/domains/python.rst

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -563,43 +563,57 @@ Python Signatures
563563

564564
Signatures of functions, methods and class constructors can be given like they
565565
would be written in Python.
566+
This can include default values, positional-only or keyword-only parameters,
567+
type annotations, and type parameters.
568+
For example:
566569

567-
Default values for optional arguments can be given (but if they contain commas,
568-
they will confuse the signature parser). Python 3-style argument annotations
569-
can also be given as well as return type annotations::
570+
.. code-block:: rst
571+
572+
.. py:function:: compile(source: str, filename: Path, symbol: str = 'file') -> ast.AST
570573
571-
.. py:function:: compile(source : string, filename, symbol='file') -> ast object
574+
.. py:function:: compile(source: str, filename: Path, symbol: str = 'file') -> ast.AST
575+
:no-index:
572576

573577
For functions with optional parameters that don't have default values
574578
(typically functions implemented in C extension modules without keyword
575-
argument support), you can use brackets to specify the optional parts:
579+
argument support),
580+
you can list multiple versions of the same signature in a single directive:
576581

577-
.. py:function:: compile(source[, filename[, symbol]])
578-
:no-contents-entry:
579-
:no-index-entry:
582+
.. py:function:: compile(source)
583+
compile(source, filename)
584+
compile(source, filename, symbol)
585+
:no-index:
580586

581-
It is customary to put the opening bracket before the comma.
587+
Another approach is to use square brackets to specify the optional parts.
588+
When using square brackets, it is customary to place
589+
the opening bracket before the comma (``[,``).
590+
591+
.. py:function:: compile(source[, filename[, symbol]])
592+
:no-index:
582593

583594
Python 3.12 introduced *type parameters*, which are type variables
584-
declared directly within the class or function definition:
595+
declared directly within the class or function definition:
585596

586597
.. code-block:: python
587598
588599
class AnimalList[AnimalT](list[AnimalT]):
589-
...
600+
...
590601
591602
def add[T](a: T, b: T) -> T:
592-
return a + b
603+
return a + b
593604
594-
The corresponding reStructuredText documentation would be:
605+
The corresponding reStructuredText markup would be:
595606

596607
.. code-block:: rst
597608
598609
.. py:class:: AnimalList[AnimalT]
599610
600611
.. py:function:: add[T](a: T, b: T) -> T
601612
602-
See :pep:`695` and :pep:`696` for details and the full specification.
613+
.. seealso::
614+
615+
:pep:`695` and :pep:`696`, for details and the full specification.
616+
603617

604618
.. _info-field-lists:
605619

0 commit comments

Comments
 (0)