@@ -192,12 +192,14 @@ declarations:
192
192
The following directives are provided for module and class contents:
193
193
194
194
.. rst :directive :: .. py:function:: name(parameters)
195
+ .. py:function:: name[type parameters](parameters)
195
196
196
197
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::
199
200
200
201
.. py:function:: Timer.repeat(repeat=3, number=1000000)
202
+ .. py:function:: add[T](x: T, y: T) -> T
201
203
202
204
For methods you should use :rst:dir: `py:method `.
203
205
@@ -240,6 +242,15 @@ The following directives are provided for module and class contents:
240
242
241
243
.. versionadded:: 7.1
242
244
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
+
243
254
244
255
.. rst :directive :: .. py:data:: name
245
256
@@ -274,6 +285,8 @@ The following directives are provided for module and class contents:
274
285
the module specified by :rst:dir:`py:currentmodule`.
275
286
276
287
.. rst :directive :: .. py:exception:: name
288
+ .. py:exception:: name(parameters)
289
+ .. py:exception:: name[type parmeters](parameters)
277
290
278
291
Describes an exception class. The signature can, but need not include
279
292
parentheses with constructor arguments.
@@ -293,12 +306,27 @@ The following directives are provided for module and class contents:
293
306
Describe the location where the object is defined. The default value is
294
307
the module specified by :rst:dir:`py:currentmodule`.
295
308
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
+
296
323
.. rst :directive :: .. py:class:: name
297
324
.. py:class:: name(parameters)
325
+ .. py:class:: name[type parmeters](parameters)
298
326
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 `.
302
330
303
331
Methods and attributes belonging to the class should be placed in this
304
332
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:
348
376
349
377
.. versionadded:: 7.1
350
378
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
+
351
386
.. rst :directive :: .. py:attribute:: name
352
387
353
388
Describes an object data attribute. The description should include
@@ -410,6 +445,7 @@ The following directives are provided for module and class contents:
410
445
the module specified by :rst:dir:`py:currentmodule`.
411
446
412
447
.. rst :directive :: .. py:method:: name(parameters)
448
+ .. py:method:: name[type parameters](parameters)
413
449
414
450
Describes an object method. The parameters should not include the ``self ``
415
451
parameter. The description should include similar information to that
@@ -469,6 +505,15 @@ The following directives are provided for module and class contents:
469
505
470
506
.. versionadded:: 7.1
471
507
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
+
472
517
.. rst:directive:option:: staticmethod
473
518
:type: no value
474
519
@@ -478,19 +523,22 @@ The following directives are provided for module and class contents:
478
523
479
524
480
525
.. rst :directive :: .. py:staticmethod:: name(parameters)
526
+ .. py:staticmethod:: name[type parameters](parameters)
481
527
482
528
Like :rst:dir: `py:method `, but indicates that the method is a static method.
483
529
484
530
.. versionadded :: 0.4
485
531
486
532
.. rst :directive :: .. py:classmethod:: name(parameters)
533
+ .. py:classmethod:: name[type parameters](parameters)
487
534
488
535
Like :rst:dir: `py:method `, but indicates that the method is a class method.
489
536
490
537
.. versionadded :: 0.6
491
538
492
539
.. rst :directive :: .. py:decorator:: name
493
540
.. py:decorator:: name(parameters)
541
+ .. py:decorator:: name[type parameters](parameters)
494
542
495
543
Describes a decorator function. The signature should represent the usage as
496
544
a decorator. For example, given the functions
@@ -531,8 +579,18 @@ The following directives are provided for module and class contents:
531
579
532
580
.. versionadded:: 7.1
533
581
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
+
534
591
.. rst :directive :: .. py:decoratormethod:: name
535
592
.. py:decoratormethod:: name(signature)
593
+ .. py:decoratormethod:: name[type parameters](signature)
536
594
537
595
Same as :rst:dir: `py:decorator `, but for decorators that are methods.
538
596
@@ -561,6 +619,13 @@ argument support), you can use brackets to specify the optional parts:
561
619
562
620
It is customary to put the opening bracket before the comma.
563
621
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
+
564
629
.. _info-field-lists :
565
630
566
631
Info field lists
0 commit comments