Skip to content

Commit 3195da0

Browse files
authored
gh-105812: Use the :deco: role in place of manual decorator markup (#139619)
1 parent 46de475 commit 3195da0

File tree

13 files changed

+38
-39
lines changed

13 files changed

+38
-39
lines changed

Doc/library/collections.abc.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ Collections Abstract Base Classes -- Detailed Descriptions
336336

337337
.. note::
338338
In CPython, generator-based coroutines (:term:`generators <generator>`
339-
decorated with :func:`@types.coroutine <types.coroutine>`) are
339+
decorated with :deco:`types.coroutine`) are
340340
*awaitables*, even though they do not have an :meth:`~object.__await__` method.
341341
Using ``isinstance(gencoro, Awaitable)`` for them will return ``False``.
342342
Use :func:`inspect.isawaitable` to detect them.
@@ -354,7 +354,7 @@ Collections Abstract Base Classes -- Detailed Descriptions
354354

355355
.. note::
356356
In CPython, generator-based coroutines (:term:`generators <generator>`
357-
decorated with :func:`@types.coroutine <types.coroutine>`) are
357+
decorated with :deco:`types.coroutine`) are
358358
*awaitables*, even though they do not have an :meth:`~object.__await__` method.
359359
Using ``isinstance(gencoro, Coroutine)`` for them will return ``False``.
360360
Use :func:`inspect.isawaitable` to detect them.

Doc/library/dataclasses.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ Module contents
317317
:func:`!field`, then the class attribute for this field will be
318318
replaced by the specified *default* value. If *default* is not
319319
provided, then the class attribute will be deleted. The intent is
320-
that after the :func:`@dataclass <dataclass>` decorator runs, the class
320+
that after the :deco:`dataclass` decorator runs, the class
321321
attributes will all contain the default values for the fields, just
322322
as if the default value itself were specified. For example,
323323
after::
@@ -427,20 +427,20 @@ Module contents
427427
:data:`typing.Any` is used for ``type``. The values of *init*,
428428
*repr*, *eq*, *order*, *unsafe_hash*, *frozen*,
429429
*match_args*, *kw_only*, *slots*, and *weakref_slot* have
430-
the same meaning as they do in :func:`@dataclass <dataclass>`.
430+
the same meaning as they do in :deco:`dataclass`.
431431

432432
If *module* is defined, the :attr:`!__module__` attribute
433433
of the dataclass is set to that value.
434434
By default, it is set to the module name of the caller.
435435

436436
The *decorator* parameter is a callable that will be used to create the dataclass.
437437
It should take the class object as a first argument and the same keyword arguments
438-
as :func:`@dataclass <dataclass>`. By default, the :func:`@dataclass <dataclass>`
438+
as :deco:`dataclass`. By default, the :deco:`dataclass`
439439
function is used.
440440

441441
This function is not strictly required, because any Python
442442
mechanism for creating a new class with :attr:`~object.__annotations__` can
443-
then apply the :func:`@dataclass <dataclass>` function to convert that class to
443+
then apply the :deco:`dataclass` function to convert that class to
444444
a dataclass. This function is provided as a convenience. For
445445
example::
446446

@@ -569,7 +569,7 @@ Post-init processing
569569
def __post_init__(self):
570570
self.c = self.a + self.b
571571

572-
The :meth:`~object.__init__` method generated by :func:`@dataclass <dataclass>` does not call base
572+
The :meth:`~object.__init__` method generated by :deco:`dataclass` does not call base
573573
class :meth:`!__init__` methods. If the base class has an :meth:`!__init__` method
574574
that has to be called, it is common to call this method in a
575575
:meth:`__post_init__` method::
@@ -599,7 +599,7 @@ parameters to :meth:`!__post_init__`. Also see the warning about how
599599
Class variables
600600
---------------
601601

602-
One of the few places where :func:`@dataclass <dataclass>` actually inspects the type
602+
One of the few places where :deco:`dataclass` actually inspects the type
603603
of a field is to determine if a field is a class variable as defined
604604
in :pep:`526`. It does this by checking if the type of the field is
605605
:data:`typing.ClassVar`. If a field is a ``ClassVar``, it is excluded
@@ -612,7 +612,7 @@ module-level :func:`fields` function.
612612
Init-only variables
613613
-------------------
614614

615-
Another place where :func:`@dataclass <dataclass>` inspects a type annotation is to
615+
Another place where :deco:`dataclass` inspects a type annotation is to
616616
determine if a field is an init-only variable. It does this by seeing
617617
if the type of a field is of type :class:`InitVar`. If a field
618618
is an :class:`InitVar`, it is considered a pseudo-field called an init-only
@@ -646,7 +646,7 @@ Frozen instances
646646
----------------
647647

648648
It is not possible to create truly immutable Python objects. However,
649-
by passing ``frozen=True`` to the :func:`@dataclass <dataclass>` decorator you can
649+
by passing ``frozen=True`` to the :deco:`dataclass` decorator you can
650650
emulate immutability. In that case, dataclasses will add
651651
:meth:`~object.__setattr__` and :meth:`~object.__delattr__` methods to the class. These
652652
methods will raise a :exc:`FrozenInstanceError` when invoked.
@@ -662,7 +662,7 @@ must use :meth:`!object.__setattr__`.
662662
Inheritance
663663
-----------
664664

665-
When the dataclass is being created by the :func:`@dataclass <dataclass>` decorator,
665+
When the dataclass is being created by the :deco:`dataclass` decorator,
666666
it looks through all of the class's base classes in reverse MRO (that
667667
is, starting at :class:`object`) and, for each dataclass that it finds,
668668
adds the fields from that base class to an ordered mapping of fields.
@@ -786,7 +786,7 @@ for :attr:`!x` when creating a class instance will share the same copy
786786
of :attr:`!x`. Because dataclasses just use normal Python class
787787
creation they also share this behavior. There is no general way
788788
for Data Classes to detect this condition. Instead, the
789-
:func:`@dataclass <dataclass>` decorator will raise a :exc:`ValueError` if it
789+
:deco:`dataclass` decorator will raise a :exc:`ValueError` if it
790790
detects an unhashable default parameter. The assumption is that if
791791
a value is unhashable, it is mutable. This is a partial solution,
792792
but it does protect against many common errors.
@@ -820,7 +820,7 @@ default value have the following special behaviors:
820820
:meth:`~object.__get__` or :meth:`!__set__` method is called rather than returning or
821821
overwriting the descriptor object.
822822

823-
* To determine whether a field contains a default value, :func:`@dataclass <dataclass>`
823+
* To determine whether a field contains a default value, :deco:`dataclass`
824824
will call the descriptor's :meth:`!__get__` method using its class access
825825
form: ``descriptor.__get__(obj=None, type=cls)``. If the
826826
descriptor returns a value in this case, it will be used as the

Doc/library/functools.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ The :mod:`functools` module defines the following functions:
690690
return not arg
691691

692692
``@singledispatchmethod`` supports nesting with other decorators such as
693-
:func:`@classmethod<classmethod>`. Note that to allow for
693+
:deco:`classmethod`. Note that to allow for
694694
``dispatcher.register``, ``singledispatchmethod`` must be the *outer most*
695695
decorator. Here is the ``Negator`` class with the ``neg`` methods bound to
696696
the class, rather than an instance of the class::
@@ -712,8 +712,7 @@ The :mod:`functools` module defines the following functions:
712712
return not arg
713713

714714
The same pattern can be used for other similar decorators:
715-
:func:`@staticmethod<staticmethod>`,
716-
:func:`@abstractmethod<abc.abstractmethod>`, and others.
715+
:deco:`staticmethod`, :deco:`~abc.abstractmethod`, and others.
717716

718717
.. versionadded:: 3.8
719718

Doc/library/typing.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ These can be used as types in annotations. They all support subscription using
13901390
Using ``Annotated[T, x]`` as an annotation still allows for static
13911391
typechecking of ``T``, as type checkers will simply ignore the metadata ``x``.
13921392
In this way, ``Annotated`` differs from the
1393-
:func:`@no_type_check <no_type_check>` decorator, which can also be used for
1393+
:deco:`no_type_check` decorator, which can also be used for
13941394
adding annotations outside the scope of the typing system, but
13951395
completely disables typechecking for a function or class.
13961396

@@ -2815,7 +2815,7 @@ Protocols
28152815
---------
28162816

28172817
The following protocols are provided by the :mod:`!typing` module. All are decorated
2818-
with :func:`@runtime_checkable <runtime_checkable>`.
2818+
with :deco:`runtime_checkable`.
28192819

28202820
.. class:: SupportsAbs
28212821

@@ -2996,7 +2996,7 @@ Functions and decorators
29962996
The presence of ``@dataclass_transform()`` tells a static type checker that the
29972997
decorated object performs runtime "magic" that
29982998
transforms a class in a similar way to
2999-
:func:`@dataclasses.dataclass <dataclasses.dataclass>`.
2999+
:deco:`dataclasses.dataclass`.
30003000

30013001
Example usage with a decorator function:
30023002

@@ -3034,14 +3034,14 @@ Functions and decorators
30343034

30353035
The ``CustomerModel`` classes defined above will
30363036
be treated by type checkers similarly to classes created with
3037-
:func:`@dataclasses.dataclass <dataclasses.dataclass>`.
3037+
:deco:`dataclasses.dataclass`.
30383038
For example, type checkers will assume these classes have
30393039
``__init__`` methods that accept ``id`` and ``name``.
30403040

30413041
The decorated class, metaclass, or function may accept the following bool
30423042
arguments which type checkers will assume have the same effect as they
30433043
would have on the
3044-
:func:`@dataclasses.dataclass<dataclasses.dataclass>` decorator: ``init``,
3044+
:deco:`dataclasses.dataclass` decorator: ``init``,
30453045
``eq``, ``order``, ``unsafe_hash``, ``frozen``, ``match_args``,
30463046
``kw_only``, and ``slots``. It must be possible for the value of these
30473047
arguments (``True`` or ``False``) to be statically evaluated.
@@ -3169,12 +3169,12 @@ Functions and decorators
31693169

31703170
.. function:: get_overloads(func)
31713171

3172-
Return a sequence of :func:`@overload <overload>`-decorated definitions for
3172+
Return a sequence of :deco:`overload`-decorated definitions for
31733173
*func*.
31743174

31753175
*func* is the function object for the implementation of the
31763176
overloaded function. For example, given the definition of ``process`` in
3177-
the documentation for :func:`@overload <overload>`,
3177+
the documentation for :deco:`overload`,
31783178
``get_overloads(process)`` will return a sequence of three function objects
31793179
for the three defined overloads. If called on a function with no overloads,
31803180
``get_overloads()`` returns an empty sequence.
@@ -3331,7 +3331,7 @@ Introspection helpers
33313331
If *globalns* or *localns* is not given, appropriate namespace
33323332
dictionaries are inferred from *obj*.
33333333
* ``None`` is replaced with :class:`types.NoneType`.
3334-
* If :func:`@no_type_check <no_type_check>` has been applied to *obj*, an
3334+
* If :deco:`no_type_check` has been applied to *obj*, an
33353335
empty dictionary is returned.
33363336
* If *obj* is a class ``C``, the function returns a dictionary that merges
33373337
annotations from ``C``'s base classes with those on ``C`` directly. This

Doc/library/warnings.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ Available Functions
590590
The deprecation message passed to the decorator is saved in the
591591
``__deprecated__`` attribute on the decorated object.
592592
If applied to an overload, the decorator
593-
must be after the :func:`@overload <typing.overload>` decorator
593+
must be after the :deco:`~typing.overload` decorator
594594
for the attribute to exist on the overload as returned by
595595
:func:`typing.get_overloads`.
596596

Doc/reference/datamodel.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,7 @@ instance dictionary. In contrast, non-data descriptors can be overridden by
25582558
instances.
25592559

25602560
Python methods (including those decorated with
2561-
:func:`@staticmethod <staticmethod>` and :func:`@classmethod <classmethod>`) are
2561+
:deco:`staticmethod` and :deco:`classmethod`) are
25622562
implemented as non-data descriptors. Accordingly, instances can redefine and
25632563
override methods. This allows individual instances to acquire behaviors that
25642564
differ from other instances of the same class.
@@ -2993,7 +2993,7 @@ class method ``__class_getitem__()``.
29932993

29942994
When defined on a class, ``__class_getitem__()`` is automatically a class
29952995
method. As such, there is no need for it to be decorated with
2996-
:func:`@classmethod<classmethod>` when it is defined.
2996+
:deco:`classmethod` when it is defined.
29972997

29982998

29992999
The purpose of *__class_getitem__*

Doc/whatsnew/2.7.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,8 @@ Some smaller changes made to the core Python language are:
858858

859859
.. XXX bytearray doesn't seem to be documented
860860
861-
* When using :class:`@classmethod <classmethod>` and
862-
:class:`@staticmethod <staticmethod>` to wrap
861+
* When using :deco:`classmethod` and
862+
:deco:`staticmethod` to wrap
863863
methods as class or static methods, the wrapper object now
864864
exposes the wrapped function as their :attr:`~method.__func__`
865865
attribute.

Doc/whatsnew/3.10.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,8 @@ Other Language Changes
847847
respectively.
848848
(Contributed by Joshua Bronson, Daniel Pope, and Justin Wang in :issue:`31861`.)
849849
850-
* Static methods (:func:`@staticmethod <staticmethod>`) and class methods
851-
(:func:`@classmethod <classmethod>`) now inherit the method attributes
850+
* Static methods (:deco:`staticmethod`) and class methods
851+
(:deco:`classmethod`) now inherit the method attributes
852852
(``__module__``, ``__name__``, ``__qualname__``, ``__doc__``,
853853
``__annotations__``) and have a new ``__wrapped__`` attribute.
854854
Moreover, static methods are now callable as regular functions.

Misc/NEWS.d/3.10.0b1.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ the heap. Should speed up dispatch in the interpreter.
402402
.. nonce: eUn4p5
403403
.. section: Core and Builtins
404404
405-
Static methods (:func:`@staticmethod <staticmethod>`) and class methods
406-
(:func:`@classmethod <classmethod>`) now inherit the method attributes
405+
Static methods (:deco:`staticmethod`) and class methods
406+
(:deco:`classmethod`) now inherit the method attributes
407407
(``__module__``, ``__name__``, ``__qualname__``, ``__doc__``,
408408
``__annotations__``) and have a new ``__wrapped__`` attribute. Patch by
409409
Victor Stinner.
@@ -454,7 +454,7 @@ file locations.
454454
.. nonce: VSF3vg
455455
.. section: Core and Builtins
456456
457-
Static methods (:func:`@staticmethod <staticmethod>`) are now callable as
457+
Static methods (:deco:`staticmethod`) are now callable as
458458
regular functions. Patch by Victor Stinner.
459459

460460
..

Misc/NEWS.d/3.11.0a1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ support for Metadata 2.2.
29532953
.. nonce: xTUyyX
29542954
.. section: Library
29552955
2956-
Remove the :func:`@asyncio.coroutine <asyncio.coroutine>` :term:`decorator`
2956+
Remove the :deco:`asyncio.coroutine` :term:`decorator`
29572957
enabling legacy generator-based coroutines to be compatible with async/await
29582958
code; remove :class:`asyncio.coroutines.CoroWrapper` used for wrapping
29592959
legacy coroutine objects in the debug mode. The decorator has been

0 commit comments

Comments
 (0)