Skip to content

Commit 5001935

Browse files
committed
gh-105812: Make use of the Sphinx deco role in documentation, part 1
For the following decorators: `classmethod`, `staticmethod`, `property`, ABC decorators, enum decorators, `functools.lru_cache`, `functools.cache`.
1 parent 41712c4 commit 5001935

26 files changed

+90
-93
lines changed

Doc/c-api/structures.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ method.
419419
420420
The method will be passed the type object as the first parameter rather
421421
than an instance of the type. This is used to create *class methods*,
422-
similar to what is created when using the :func:`classmethod` built-in
423-
function.
422+
similar to what is created when using the :deco:`classmethod` built-in
423+
decorator.
424424
425425
426426
.. c:macro:: METH_STATIC
@@ -429,7 +429,7 @@ method.
429429
430430
The method will be passed ``NULL`` as the first parameter rather than an
431431
instance of the type. This is used to create *static methods*, similar to
432-
what is created when using the :func:`staticmethod` built-in function.
432+
what is created when using the :deco:`staticmethod` built-in decorator.
433433
434434
One other constant controls whether a method is loaded in place of another
435435
definition with the same method name.

Doc/faq/programming.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ How do I cache method calls?
19951995
----------------------------
19961996

19971997
The two principal tools for caching methods are
1998-
:func:`functools.cached_property` and :func:`functools.lru_cache`. The
1998+
:deco:`functools.cached_property` and :deco:`functools.lru_cache`. The
19991999
former stores results at the instance level and the latter at the class
20002000
level.
20012001

Doc/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ Glossary
366366
decorator
367367
A function returning another function, usually applied as a function
368368
transformation using the ``@wrapper`` syntax. Common examples for
369-
decorators are :func:`classmethod` and :func:`staticmethod`.
369+
decorators are :deco:`classmethod` and :deco:`staticmethod`.
370370

371371
The decorator syntax is merely syntactic sugar, the following two
372372
function definitions are semantically equivalent::

Doc/howto/descriptor.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This guide has four major sections:
2828
4) The last section has pure Python equivalents for built-in descriptors that
2929
are written in C. Read this if you're curious about how functions turn
3030
into bound methods or about the implementation of common tools like
31-
:func:`classmethod`, :func:`staticmethod`, :func:`property`, and
31+
:deco:`classmethod`, :deco:`staticmethod`, :deco:`property`, and
3232
:term:`__slots__`.
3333

3434

@@ -317,8 +317,8 @@ Descriptors invert that relationship and allow the data being looked-up to
317317
have a say in the matter.
318318

319319
Descriptors are used throughout the language. It is how functions turn into
320-
bound methods. Common tools like :func:`classmethod`, :func:`staticmethod`,
321-
:func:`property`, and :func:`functools.cached_property` are all implemented as
320+
bound methods. Common tools like :deco:`classmethod`, :deco:`staticmethod`,
321+
:deco:`property`, and :deco:`functools.cached_property` are all implemented as
322322
descriptors.
323323

324324

@@ -1326,7 +1326,7 @@ example calls are unexciting:
13261326
30
13271327

13281328
Using the non-data descriptor protocol, a pure Python version of
1329-
:func:`staticmethod` would look like this:
1329+
:deco:`staticmethod` would look like this:
13301330

13311331
.. testcode::
13321332

@@ -1466,7 +1466,7 @@ Now a new dictionary of unique keys can be constructed like this:
14661466
{'a': None, 'b': None, 'r': None, 'c': None, 'd': None}
14671467

14681468
Using the non-data descriptor protocol, a pure Python version of
1469-
:func:`classmethod` would look like this:
1469+
:deco:`classmethod` would look like this:
14701470

14711471
.. testcode::
14721472

@@ -1604,7 +1604,7 @@ matters when a large number of instances are going to be created.
16041604
4. Improves speed. Reading instance variables is 35% faster with
16051605
``__slots__`` (as measured with Python 3.10 on an Apple M1 processor).
16061606

1607-
5. Blocks tools like :func:`functools.cached_property` which require an
1607+
5. Blocks tools like :deco:`functools.cached_property` which require an
16081608
instance dictionary to function correctly:
16091609

16101610
.. testcode::

Doc/howto/enum.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ Ensuring unique enumeration values
256256
----------------------------------
257257

258258
By default, enumerations allow multiple names as aliases for the same value.
259-
When this behavior isn't desired, you can use the :func:`unique` decorator::
259+
When this behavior isn't desired, you can use the :deco:`unique` decorator::
260260

261261
>>> from enum import Enum, unique
262262
>>> @unique

Doc/library/abc.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,17 @@ The :mod:`!abc` module also provides the following decorator:
170170
or is derived from it. A class that has a metaclass derived from
171171
:class:`!ABCMeta` cannot be instantiated unless all of its abstract methods
172172
and properties are overridden. The abstract methods can be called using any
173-
of the normal 'super' call mechanisms. :func:`!abstractmethod` may be used
173+
of the normal 'super' call mechanisms. :deco:`!abstractmethod` may be used
174174
to declare abstract methods for properties and descriptors.
175175

176176
Dynamically adding abstract methods to a class, or attempting to modify the
177177
abstraction status of a method or class once it is created, are only
178178
supported using the :func:`update_abstractmethods` function. The
179-
:func:`!abstractmethod` only affects subclasses derived using regular
179+
:deco:`!abstractmethod` only affects subclasses derived using regular
180180
inheritance; "virtual subclasses" registered with the ABC's
181181
:meth:`~ABCMeta.register` method are not affected.
182182

183-
When :func:`!abstractmethod` is applied in combination with other method
183+
When :deco:`!abstractmethod` is applied in combination with other method
184184
descriptors, it should be applied as the innermost decorator, as shown in
185185
the following usage examples::
186186

@@ -218,7 +218,7 @@ The :mod:`!abc` module also provides the following decorator:
218218
the descriptor must identify itself as abstract using
219219
:attr:`!__isabstractmethod__`. In general, this attribute should be ``True``
220220
if any of the methods used to compose the descriptor are abstract. For
221-
example, Python's built-in :class:`property` does the equivalent of::
221+
example, Python's built-in :deco:`property` does the equivalent of::
222222

223223
class Descriptor:
224224
...
@@ -242,13 +242,13 @@ The :mod:`!abc` module also supports the following legacy decorators:
242242

243243
.. versionadded:: 3.2
244244
.. deprecated:: 3.3
245-
It is now possible to use :class:`classmethod` with
246-
:func:`abstractmethod`, making this decorator redundant.
245+
It is now possible to use :deco:`classmethod` with
246+
:deco:`abstractmethod`, making this decorator redundant.
247247

248-
A subclass of the built-in :func:`classmethod`, indicating an abstract
249-
classmethod. Otherwise it is similar to :func:`abstractmethod`.
248+
A subclass of the built-in :class:`classmethod`, indicating an abstract
249+
classmethod. Otherwise it is similar to :deco:`abstractmethod`.
250250

251-
This special case is deprecated, as the :func:`classmethod` decorator
251+
This special case is deprecated, as the :deco:`classmethod` decorator
252252
is now correctly identified as abstract when applied to an abstract
253253
method::
254254

@@ -263,13 +263,13 @@ The :mod:`!abc` module also supports the following legacy decorators:
263263

264264
.. versionadded:: 3.2
265265
.. deprecated:: 3.3
266-
It is now possible to use :class:`staticmethod` with
267-
:func:`abstractmethod`, making this decorator redundant.
266+
It is now possible to use :deco:`staticmethod` with
267+
:deco:`abstractmethod`, making this decorator redundant.
268268

269-
A subclass of the built-in :func:`staticmethod`, indicating an abstract
270-
staticmethod. Otherwise it is similar to :func:`abstractmethod`.
269+
A subclass of the built-in :class:`staticmethod`, indicating an abstract
270+
staticmethod. Otherwise it is similar to :deco:`abstractmethod`.
271271

272-
This special case is deprecated, as the :func:`staticmethod` decorator
272+
This special case is deprecated, as the :deco:`staticmethod` decorator
273273
is now correctly identified as abstract when applied to an abstract
274274
method::
275275

@@ -283,14 +283,14 @@ The :mod:`!abc` module also supports the following legacy decorators:
283283
.. decorator:: abstractproperty
284284

285285
.. deprecated:: 3.3
286-
It is now possible to use :class:`property`, :meth:`property.getter`,
286+
It is now possible to use :deco:`property`, :meth:`property.getter`,
287287
:meth:`property.setter` and :meth:`property.deleter` with
288-
:func:`abstractmethod`, making this decorator redundant.
288+
:deco:`abstractmethod`, making this decorator redundant.
289289

290-
A subclass of the built-in :func:`property`, indicating an abstract
290+
A subclass of the built-in :class:`property`, indicating an abstract
291291
property.
292292

293-
This special case is deprecated, as the :func:`property` decorator
293+
This special case is deprecated, as the :deco:`property` decorator
294294
is now correctly identified as abstract when applied to an abstract
295295
method::
296296

Doc/library/bisect.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ thoughts in mind:
132132
they are used. Consequently, if the search functions are used in a loop,
133133
the key function may be called again and again on the same array elements.
134134
If the key function isn't fast, consider wrapping it with
135-
:py:func:`functools.cache` to avoid duplicate computations. Alternatively,
135+
:py:deco:`functools.cache` to avoid duplicate computations. Alternatively,
136136
consider searching an array of precomputed keys to locate the insertion
137137
point (as shown in the examples section below).
138138

Doc/library/collections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ original insertion position is changed and moved to the end::
12161216
self.move_to_end(key)
12171217

12181218
An :class:`OrderedDict` would also be useful for implementing
1219-
variants of :func:`functools.lru_cache`:
1219+
variants of :deco:`functools.lru_cache`:
12201220

12211221
.. testcode::
12221222

Doc/library/contextlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Functions and classes provided:
8888
the exception has been handled, and execution will resume with the statement
8989
immediately following the :keyword:`!with` statement.
9090

91-
:func:`contextmanager` uses :class:`ContextDecorator` so the context managers
91+
:deco:`contextmanager` uses :class:`ContextDecorator` so the context managers
9292
it creates can be used as decorators as well as in :keyword:`with` statements.
9393
When used as a decorator, a new generator instance is implicitly created on
9494
each function call (this allows the otherwise "one-shot" context managers

Doc/library/ctypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ object with an :attr:`!_as_parameter_` attribute::
446446
>>>
447447

448448
If you don't want to store the instance's data in the :attr:`!_as_parameter_`
449-
instance variable, you could define a :class:`property` which makes the
449+
instance variable, you could define a :deco:`property` which makes the
450450
attribute available on request.
451451

452452

0 commit comments

Comments
 (0)