@@ -1619,8 +1619,9 @@ are always available. They are listed here in alphabetical order.
1619
1619
The ``@staticmethod `` form is a function :term: `decorator ` -- see
1620
1620
:ref: `function ` for details.
1621
1621
1622
- A static method can be called either on the class (such as ``C.f() ``) or on an instance (such
1623
- as ``C().f() ``).
1622
+ A static method can be called either on the class (such as ``C.f() ``) or on
1623
+ an instance (such as ``C().f() ``). Moreover, they can be called as regular
1624
+ functions (such as ``f() ``).
1624
1625
1625
1626
Static methods in Python are similar to those found in Java or C++. Also see
1626
1627
: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.
1632
1633
body and you want to avoid the automatic transformation to instance
1633
1634
method. For these cases, use this idiom::
1634
1635
1636
+ def regular_function():
1637
+ ...
1638
+
1635
1639
class C:
1636
- builtin_open = staticmethod(open )
1640
+ method = staticmethod(regular_function )
1637
1641
1638
1642
For more information on static methods, see :ref: `types `.
1639
1643
1640
1644
.. versionchanged :: 3.10
1641
1645
Static methods now inherit the method attributes (``__module__ ``,
1642
- ``__name__ ``, ``__qualname__ ``, ``__doc__ `` and ``__annotations__ ``) and
1643
- have a new ``__wrapped__ `` attribute.
1646
+ ``__name__ ``, ``__qualname__ ``, ``__doc__ `` and ``__annotations__ ``),
1647
+ have a new ``__wrapped__ `` attribute, and are now callable as regular
1648
+ functions.
1644
1649
1645
1650
1646
1651
.. index ::
0 commit comments