summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-04-11 22:21:22 (GMT)
committerGitHub <noreply@github.com>2021-04-11 22:21:22 (GMT)
commit553ee2781a37ac9d2068da3e1325a780ca79e21e (patch)
tree599710562c5961edb6d7365761da242a8c122680 /Doc
parent53114ffef1d4facf9aa5545e711abbbda66f672a (diff)
downloadcpython-553ee2781a37ac9d2068da3e1325a780ca79e21e.zip
cpython-553ee2781a37ac9d2068da3e1325a780ca79e21e.tar.gz
cpython-553ee2781a37ac9d2068da3e1325a780ca79e21e.tar.bz2
bpo-43682: Make staticmethod objects callable (GH-25117)
Static methods (@staticmethod) are now callable as regular functions.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/functions.rst15
-rw-r--r--Doc/reference/datamodel.rst5
-rw-r--r--Doc/whatsnew/3.10.rst1
3 files changed, 13 insertions, 8 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index dca8b93..30f62e6 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -1619,8 +1619,9 @@ are always available. They are listed here in alphabetical order.
The ``@staticmethod`` form is a function :term:`decorator` -- see
:ref:`function` for details.
- A static method can be called either on the class (such as ``C.f()``) or on an instance (such
- as ``C().f()``).
+ A static method can be called either on the class (such as ``C.f()``) or on
+ an instance (such as ``C().f()``). Moreover, they can be called as regular
+ functions (such as ``f()``).
Static methods in Python are similar to those found in Java or C++. Also see
:func:`classmethod` for a variant that is useful for creating alternate class
@@ -1632,15 +1633,19 @@ are always available. They are listed here in alphabetical order.
body and you want to avoid the automatic transformation to instance
method. For these cases, use this idiom::
+ def regular_function():
+ ...
+
class C:
- builtin_open = staticmethod(open)
+ method = staticmethod(regular_function)
For more information on static methods, see :ref:`types`.
.. versionchanged:: 3.10
Static methods now inherit the method attributes (``__module__``,
- ``__name__``, ``__qualname__``, ``__doc__`` and ``__annotations__``) and
- have a new ``__wrapped__`` attribute.
+ ``__name__``, ``__qualname__``, ``__doc__`` and ``__annotations__``),
+ have a new ``__wrapped__`` attribute, and are now callable as regular
+ functions.
.. index::
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 9c819b7..3b8780d 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1132,9 +1132,8 @@ Internal types
around any other object, usually a user-defined method object. When a static
method object is retrieved from a class or a class instance, the object actually
returned is the wrapped object, which is not subject to any further
- transformation. Static method objects are not themselves callable, although the
- objects they wrap usually are. Static method objects are created by the built-in
- :func:`staticmethod` constructor.
+ transformation. Static method objects are also callable. Static method
+ objects are created by the built-in :func:`staticmethod` constructor.
Class method objects
A class method object, like a static method object, is a wrapper around another
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 50c8d53..9f6b7a4 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -623,6 +623,7 @@ Other Language Changes
(:func:`@classmethod <classmethod>`) now inherit the method attributes
(``__module__``, ``__name__``, ``__qualname__``, ``__doc__``,
``__annotations__``) and have a new ``__wrapped__`` attribute.
+ Moreover, static methods are now callable as regular functions.
(Contributed by Victor Stinner in :issue:`43682`.)