Skip to content

Commit

Permalink
bpo-19072: Classmethod can wrap other classmethod like descriptors (G…
Browse files Browse the repository at this point in the history
…H-29634)

staticmethod() also became callable in Python 3.10.

See: b83861f.
  • Loading branch information
rhettinger committed Nov 19, 2021
1 parent d32316a commit e34809e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Doc/howto/descriptor.rst
Expand Up @@ -1264,6 +1264,9 @@ Using the non-data descriptor protocol, a pure Python version of
def __get__(self, obj, objtype=None):
return self.f

def __call__(self, *args, **kwds):
return self.f(*args, **kwds)
.. testcode::
:hide:

Expand All @@ -1272,13 +1275,17 @@ Using the non-data descriptor protocol, a pure Python version of
def f(x):
return x * 10

wrapped_ord = StaticMethod(ord)

.. doctest::
:hide:

>>> E_sim.f(3)
30
>>> E_sim().f(3)
30
>>> wrapped_ord('A')
65


Class methods
Expand Down Expand Up @@ -1344,7 +1351,7 @@ Using the non-data descriptor protocol, a pure Python version of
if cls is None:
cls = type(obj)
if hasattr(type(self.f), '__get__'):
return self.f.__get__(cls)
return self.f.__get__(cls, cls)
return MethodType(self.f, cls)

.. testcode::
Expand Down

0 comments on commit e34809e

Please sign in to comment.