summaryrefslogtreecommitdiffstats
path: root/Doc/howto
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-11-19 19:12:16 (GMT)
committerGitHub <noreply@github.com>2021-11-19 19:12:16 (GMT)
commitbbe3c57c865439f2194eb760a4362b5506d221a7 (patch)
treebb41f41dc8d8565b48f3e4ea6a34694510b0614e /Doc/howto
parent9501e8d3a339c5a9217b7d90275d2a8c8cba5d13 (diff)
downloadcpython-bbe3c57c865439f2194eb760a4362b5506d221a7.zip
cpython-bbe3c57c865439f2194eb760a4362b5506d221a7.tar.gz
cpython-bbe3c57c865439f2194eb760a4362b5506d221a7.tar.bz2
bpo-19072: Classmethod can wrap other classmethod like descriptors (GH-29634) (GH-29643)
staticmethod() also became callable in Python 3.10. See: b83861f02. (cherry picked from commit e34809e1c2a09478f4e0651d551c9c12d3c556ab) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Diffstat (limited to 'Doc/howto')
-rw-r--r--Doc/howto/descriptor.rst9
1 files changed, 8 insertions, 1 deletions
diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst
index 575caeb..6ce062d 100644
--- a/Doc/howto/descriptor.rst
+++ b/Doc/howto/descriptor.rst
@@ -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:
@@ -1272,6 +1275,8 @@ Using the non-data descriptor protocol, a pure Python version of
def f(x):
return x * 10
+ wrapped_ord = StaticMethod(ord)
+
.. doctest::
:hide:
@@ -1279,6 +1284,8 @@ Using the non-data descriptor protocol, a pure Python version of
30
>>> E_sim().f(3)
30
+ >>> wrapped_ord('A')
+ 65
Class methods
@@ -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::