Skip to content

Commit 205dd4e

Browse files
miss-islingtonmerwok
authored andcommitted
[3.6] bpo-31567: add or fix decorator markup in docs (GH-3959) (GH-3966)
(cherry picked from commit 0e61e67)
1 parent 5f90800 commit 205dd4e

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

Doc/library/abc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ The :mod:`abc` module also provides the following decorators:
278278
:func:`abstractmethod`, making this decorator redundant.
279279

280280

281-
.. decorator:: abstractproperty(fget=None, fset=None, fdel=None, doc=None)
281+
.. decorator:: abstractproperty
282282

283283
A subclass of the built-in :func:`property`, indicating an abstract
284284
property.

Doc/library/functions.rst

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ are always available. They are listed here in alphabetical order.
182182
base 16). :exc:`ValueError` will be raised if *i* is outside that range.
183183

184184

185-
.. function:: classmethod(function)
185+
.. decorator:: classmethod
186186

187-
Return a class method for *function*.
187+
Transform a method into a class method.
188188

189189
A class method receives the class as implicit first argument, just like an
190190
instance method receives the instance. To declare a class method, use this
@@ -1384,9 +1384,9 @@ are always available. They are listed here in alphabetical order.
13841384

13851385
For sorting examples and a brief sorting tutorial, see :ref:`sortinghowto`.
13861386

1387-
.. function:: staticmethod(function)
1387+
.. decorator:: staticmethod
13881388

1389-
Return a static method for *function*.
1389+
Transform a method into a static method.
13901390

13911391
A static method does not receive an implicit first argument. To declare a static
13921392
method, use this idiom::
@@ -1405,12 +1405,21 @@ are always available. They are listed here in alphabetical order.
14051405
:func:`classmethod` for a variant that is useful for creating alternate class
14061406
constructors.
14071407

1408+
Like all decorators, it is also possible to call ``staticmethod`` as
1409+
a regular function and do something with its result. This is needed
1410+
in some cases where you need a reference to a function from a class
1411+
body and you want to avoid the automatic transformation to instance
1412+
method. For these cases, use this idiom:
1413+
1414+
class C:
1415+
builtin_open = staticmethod(open)
1416+
14081417
For more information on static methods, consult the documentation on the
14091418
standard type hierarchy in :ref:`types`.
14101419

1411-
.. index::
1412-
single: string; str() (built-in function)
14131420

1421+
.. index::
1422+
single: string; str() (built-in function)
14141423

14151424
.. _func-str:
14161425
.. class:: str(object='')

Doc/library/functools.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ The :mod:`functools` module defines the following functions:
264264
return value
265265

266266

267-
.. decorator:: singledispatch(default)
267+
.. decorator:: singledispatch
268268

269-
Transforms a function into a :term:`single-dispatch <single
269+
Transform a function into a :term:`single-dispatch <single
270270
dispatch>` :term:`generic function`.
271271

272272
To define a generic function, decorate it with the ``@singledispatch``

Doc/library/test.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ The :mod:`test.support` module defines the following functions:
440440
otherwise.
441441

442442

443-
.. decorator:: skip_unless_symlink()
443+
.. decorator:: skip_unless_symlink
444444

445445
A decorator for running tests that require support for symbolic links.
446446

Doc/library/typing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,17 +897,17 @@ The module defines the following classes, functions and decorators:
897897

898898
See :pep:`484` for details and comparison with other typing semantics.
899899

900-
.. decorator:: no_type_check(arg)
900+
.. decorator:: no_type_check
901901

902902
Decorator to indicate that annotations are not type hints.
903903

904-
The argument must be a class or function; if it is a class, it
904+
This works as class or function :term:`decorator`. With a class, it
905905
applies recursively to all methods defined in that class (but not
906906
to methods defined in its superclasses or subclasses).
907907

908908
This mutates the function(s) in place.
909909

910-
.. decorator:: no_type_check_decorator(decorator)
910+
.. decorator:: no_type_check_decorator
911911

912912
Decorator to give another decorator the :func:`no_type_check` effect.
913913

Lib/test/test_typing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,8 +1471,8 @@ class D(C):
14711471
def test_meta_no_type_check(self):
14721472

14731473
@no_type_check_decorator
1474-
def magic_decorator(deco):
1475-
return deco
1474+
def magic_decorator(func):
1475+
return func
14761476

14771477
self.assertEqual(magic_decorator.__name__, 'magic_decorator')
14781478

0 commit comments

Comments
 (0)