Skip to content

Commit 184e153

Browse files
committed
[3.13] pythongh-105812: Use the :deco: role in place of manual decorator markup (pythonGH-139619)
(cherry picked from commit 3195da0) Co-authored-by: Adam Turner <[email protected]>
1 parent 89a1efc commit 184e153

File tree

12 files changed

+36
-37
lines changed

12 files changed

+36
-37
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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ Module contents
320320
:func:`!field`, then the class attribute for this field will be
321321
replaced by the specified *default* value. If *default* is not
322322
provided, then the class attribute will be deleted. The intent is
323-
that after the :func:`@dataclass <dataclass>` decorator runs, the class
323+
that after the :deco:`dataclass` decorator runs, the class
324324
attributes will all contain the default values for the fields, just
325325
as if the default value itself were specified. For example,
326326
after::
@@ -430,15 +430,15 @@ Module contents
430430
:data:`typing.Any` is used for ``type``. The values of *init*,
431431
*repr*, *eq*, *order*, *unsafe_hash*, *frozen*,
432432
*match_args*, *kw_only*, *slots*, and *weakref_slot* have
433-
the same meaning as they do in :func:`@dataclass <dataclass>`.
433+
the same meaning as they do in :deco:`dataclass`.
434434

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

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

@@ -564,7 +564,7 @@ Post-init processing
564564
def __post_init__(self):
565565
self.c = self.a + self.b
566566

567-
The :meth:`~object.__init__` method generated by :func:`@dataclass <dataclass>` does not call base
567+
The :meth:`~object.__init__` method generated by :deco:`dataclass` does not call base
568568
class :meth:`!__init__` methods. If the base class has an :meth:`!__init__` method
569569
that has to be called, it is common to call this method in a
570570
:meth:`__post_init__` method::
@@ -594,7 +594,7 @@ parameters to :meth:`!__post_init__`. Also see the warning about how
594594
Class variables
595595
---------------
596596

597-
One of the few places where :func:`@dataclass <dataclass>` actually inspects the type
597+
One of the few places where :deco:`dataclass` actually inspects the type
598598
of a field is to determine if a field is a class variable as defined
599599
in :pep:`526`. It does this by checking if the type of the field is
600600
:data:`typing.ClassVar`. If a field is a ``ClassVar``, it is excluded
@@ -607,7 +607,7 @@ module-level :func:`fields` function.
607607
Init-only variables
608608
-------------------
609609

610-
Another place where :func:`@dataclass <dataclass>` inspects a type annotation is to
610+
Another place where :deco:`dataclass` inspects a type annotation is to
611611
determine if a field is an init-only variable. It does this by seeing
612612
if the type of a field is of type :class:`InitVar`. If a field
613613
is an :class:`InitVar`, it is considered a pseudo-field called an init-only
@@ -641,7 +641,7 @@ Frozen instances
641641
----------------
642642

643643
It is not possible to create truly immutable Python objects. However,
644-
by passing ``frozen=True`` to the :func:`@dataclass <dataclass>` decorator you can
644+
by passing ``frozen=True`` to the :deco:`dataclass` decorator you can
645645
emulate immutability. In that case, dataclasses will add
646646
:meth:`~object.__setattr__` and :meth:`~object.__delattr__` methods to the class. These
647647
methods will raise a :exc:`FrozenInstanceError` when invoked.
@@ -657,7 +657,7 @@ must use :meth:`!object.__setattr__`.
657657
Inheritance
658658
-----------
659659

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

818-
* To determine whether a field contains a default value, :func:`@dataclass <dataclass>`
818+
* To determine whether a field contains a default value, :deco:`dataclass`
819819
will call the descriptor's :meth:`!__get__` method using its class access
820820
form: ``descriptor.__get__(obj=None, type=cls)``. If the
821821
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
@@ -638,7 +638,7 @@ The :mod:`functools` module defines the following functions:
638638
return not arg
639639

640640
``@singledispatchmethod`` supports nesting with other decorators such as
641-
:func:`@classmethod<classmethod>`. Note that to allow for
641+
:deco:`classmethod`. Note that to allow for
642642
``dispatcher.register``, ``singledispatchmethod`` must be the *outer most*
643643
decorator. Here is the ``Negator`` class with the ``neg`` methods bound to
644644
the class, rather than an instance of the class::
@@ -660,8 +660,7 @@ The :mod:`functools` module defines the following functions:
660660
return not arg
661661

662662
The same pattern can be used for other similar decorators:
663-
:func:`@staticmethod<staticmethod>`,
664-
:func:`@abstractmethod<abc.abstractmethod>`, and others.
663+
:deco:`staticmethod`, :deco:`~abc.abstractmethod`, and others.
665664

666665
.. versionadded:: 3.8
667666

Doc/library/typing.rst

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

@@ -2733,7 +2733,7 @@ Protocols
27332733
---------
27342734

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

27382738
.. class:: SupportsAbs
27392739

@@ -2896,7 +2896,7 @@ Functions and decorators
28962896
The presence of ``@dataclass_transform()`` tells a static type checker that the
28972897
decorated object performs runtime "magic" that
28982898
transforms a class in a similar way to
2899-
:func:`@dataclasses.dataclass <dataclasses.dataclass>`.
2899+
:deco:`dataclasses.dataclass`.
29002900

29012901
Example usage with a decorator function:
29022902

@@ -2934,14 +2934,14 @@ Functions and decorators
29342934

29352935
The ``CustomerModel`` classes defined above will
29362936
be treated by type checkers similarly to classes created with
2937-
:func:`@dataclasses.dataclass <dataclasses.dataclass>`.
2937+
:deco:`dataclasses.dataclass`.
29382938
For example, type checkers will assume these classes have
29392939
``__init__`` methods that accept ``id`` and ``name``.
29402940

29412941
The decorated class, metaclass, or function may accept the following bool
29422942
arguments which type checkers will assume have the same effect as they
29432943
would have on the
2944-
:func:`@dataclasses.dataclass<dataclasses.dataclass>` decorator: ``init``,
2944+
:deco:`dataclasses.dataclass` decorator: ``init``,
29452945
``eq``, ``order``, ``unsafe_hash``, ``frozen``, ``match_args``,
29462946
``kw_only``, and ``slots``. It must be possible for the value of these
29472947
arguments (``True`` or ``False``) to be statically evaluated.
@@ -3069,12 +3069,12 @@ Functions and decorators
30693069

30703070
.. function:: get_overloads(func)
30713071

3072-
Return a sequence of :func:`@overload <overload>`-decorated definitions for
3072+
Return a sequence of :deco:`overload`-decorated definitions for
30733073
*func*.
30743074

30753075
*func* is the function object for the implementation of the
30763076
overloaded function. For example, given the definition of ``process`` in
3077-
the documentation for :func:`@overload <overload>`,
3077+
the documentation for :deco:`overload`,
30783078
``get_overloads(process)`` will return a sequence of three function objects
30793079
for the three defined overloads. If called on a function with no overloads,
30803080
``get_overloads()`` returns an empty sequence.
@@ -3231,7 +3231,7 @@ Introspection helpers
32313231
If *globalns* or *localns* is not given, appropriate namespace
32323232
dictionaries are inferred from *obj*.
32333233
* ``None`` is replaced with :class:`types.NoneType`.
3234-
* If :func:`@no_type_check <no_type_check>` has been applied to *obj*, an
3234+
* If :deco:`no_type_check` has been applied to *obj*, an
32353235
empty dictionary is returned.
32363236
* If *obj* is a class ``C``, the function returns a dictionary that merges
32373237
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
@@ -579,7 +579,7 @@ Available Functions
579579
The deprecation message passed to the decorator is saved in the
580580
``__deprecated__`` attribute on the decorated object.
581581
If applied to an overload, the decorator
582-
must be after the :func:`@overload <typing.overload>` decorator
582+
must be after the :deco:`~typing.overload` decorator
583583
for the attribute to exist on the overload as returned by
584584
:func:`typing.get_overloads`.
585585

Doc/reference/datamodel.rst

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

25042504
Python methods (including those decorated with
2505-
:func:`@staticmethod <staticmethod>` and :func:`@classmethod <classmethod>`) are
2505+
:deco:`staticmethod` and :deco:`classmethod`) are
25062506
implemented as non-data descriptors. Accordingly, instances can redefine and
25072507
override methods. This allows individual instances to acquire behaviors that
25082508
differ from other instances of the same class.
@@ -2935,7 +2935,7 @@ class method ``__class_getitem__()``.
29352935

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

29402940

29412941
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)