@@ -192,12 +192,14 @@ declarations:
192192The following directives are provided for module and class contents:
193193
194194.. rst :directive :: .. py:function:: name(parameters)
195+ .. py:function:: name[type parameters](parameters)
195196
196197 Describes a module-level function. The signature should include the
197- parameters as given in the Python function definition, see :ref: ` signatures `.
198- For example::
198+ parameters, together with optional type parameters, as given in the Python
199+ function definition, see :ref: ` signatures `. For example::
199200
200201 .. py:function:: Timer.repeat(repeat=3, number=1000000)
202+ .. py:function:: add[T](x: T, y: T) -> T
201203
202204 For methods you should use :rst:dir: `py:method `.
203205
@@ -240,6 +242,15 @@ The following directives are provided for module and class contents:
240242
241243 .. versionadded:: 7.1
242244
245+ .. rst:directive:option:: single-line-type-parameter-list
246+ :type: no value
247+
248+ Ensure that the function's type parameters are emitted on a single
249+ logical line, overriding :confval:`python_maximum_signature_line_length`
250+ and :confval:`maximum_signature_line_length`.
251+
252+ .. versionadded:: 7.2
253+
243254
244255 .. rst :directive :: .. py:data:: name
245256
@@ -274,6 +285,8 @@ The following directives are provided for module and class contents:
274285 the module specified by :rst:dir:`py:currentmodule`.
275286
276287 .. rst :directive :: .. py:exception:: name
288+ .. py:exception:: name(parameters)
289+ .. py:exception:: name[type parmeters](parameters)
277290
278291 Describes an exception class. The signature can, but need not include
279292 parentheses with constructor arguments.
@@ -293,12 +306,27 @@ The following directives are provided for module and class contents:
293306 Describe the location where the object is defined. The default value is
294307 the module specified by :rst:dir:`py:currentmodule`.
295308
309+ .. rst:directive:option:: single-line-parameter-list
310+ :type: no value
311+
312+ See :rst:dir:`py:class:single-line-parameter-list`.
313+
314+ .. versionadded:: 7.1
315+
316+ .. rst:directive:option:: single-line-type-parameter-list
317+ :type: no value
318+
319+ See :rst:dir:`py:class:single-line-type-parameter-list`.
320+
321+ .. versionadded:: 7.2
322+
296323 .. rst :directive :: .. py:class:: name
297324 .. py:class:: name(parameters)
325+ .. py:class:: name[type parmeters](parameters)
298326
299- Describes a class. The signature can optionally include parentheses with
300- parameters which will be shown as the constructor arguments. See also
301- :ref: `signatures `.
327+ Describes a class. The signature can optionally include type parameters
328+ (see :pep: ` 695 `) or parentheses with parameters which will be shown as the
329+ constructor arguments. See also :ref: `signatures `.
302330
303331 Methods and attributes belonging to the class should be placed in this
304332 directive's body. If they are placed outside, the supplied name should
@@ -348,6 +376,13 @@ The following directives are provided for module and class contents:
348376
349377 .. versionadded:: 7.1
350378
379+ .. rst:directive:option:: single-line-type-parameter-list
380+ :type: no value
381+
382+ Ensure that the class constructor's type parameters are emitted on a
383+ single logical line, overriding :confval:`python_maximum_signature_line_length`
384+ and :confval:`maximum_signature_line_length`.
385+
351386 .. rst :directive :: .. py:attribute:: name
352387
353388 Describes an object data attribute. The description should include
@@ -410,6 +445,7 @@ The following directives are provided for module and class contents:
410445 the module specified by :rst:dir:`py:currentmodule`.
411446
412447 .. rst :directive :: .. py:method:: name(parameters)
448+ .. py:method:: name[type parameters](parameters)
413449
414450 Describes an object method. The parameters should not include the ``self ``
415451 parameter. The description should include similar information to that
@@ -469,6 +505,15 @@ The following directives are provided for module and class contents:
469505
470506 .. versionadded:: 7.1
471507
508+ .. rst:directive:option:: single-line-type-parameter-list
509+ :type: no value
510+
511+ Ensure that the method's type parameters are emitted on a single logical
512+ line, overriding :confval:`python_maximum_signature_line_length` and
513+ :confval:`maximum_signature_line_length`.
514+
515+ .. versionadded:: 7.2
516+
472517 .. rst:directive:option:: staticmethod
473518 :type: no value
474519
@@ -478,19 +523,22 @@ The following directives are provided for module and class contents:
478523
479524
480525 .. rst :directive :: .. py:staticmethod:: name(parameters)
526+ .. py:staticmethod:: name[type parameters](parameters)
481527
482528 Like :rst:dir: `py:method `, but indicates that the method is a static method.
483529
484530 .. versionadded :: 0.4
485531
486532.. rst :directive :: .. py:classmethod:: name(parameters)
533+ .. py:classmethod:: name[type parameters](parameters)
487534
488535 Like :rst:dir: `py:method `, but indicates that the method is a class method.
489536
490537 .. versionadded :: 0.6
491538
492539.. rst :directive :: .. py:decorator:: name
493540 .. py:decorator:: name(parameters)
541+ .. py:decorator:: name[type parameters](parameters)
494542
495543 Describes a decorator function. The signature should represent the usage as
496544 a decorator. For example, given the functions
@@ -531,8 +579,18 @@ The following directives are provided for module and class contents:
531579
532580 .. versionadded:: 7.1
533581
582+ .. rst:directive:option:: single-line-type-parameter-list
583+ :type: no value
584+
585+ Ensure that the decorator's type parameters are emitted on a single
586+ logical line, overriding :confval:`python_maximum_signature_line_length`
587+ and :confval:`maximum_signature_line_length`.
588+
589+ .. versionadded:: 7.2
590+
534591 .. rst :directive :: .. py:decoratormethod:: name
535592 .. py:decoratormethod:: name(signature)
593+ .. py:decoratormethod:: name[type parameters](signature)
536594
537595 Same as :rst:dir: `py:decorator `, but for decorators that are methods.
538596
@@ -561,6 +619,13 @@ argument support), you can use brackets to specify the optional parts:
561619
562620It is customary to put the opening bracket before the comma.
563621
622+ Since Python 3.12, it is possible to indicate type parameters directly at the
623+ function or class definition site::
624+
625+ .. py:function:: add[T](x: T, y: T) -> T
626+
627+ See :pep: `695 ` and :pep: `696 ` for details.
628+
564629.. _info-field-lists :
565630
566631Info field lists
0 commit comments