]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-19072: Classmethod can wrap other classmethod like descriptors (GH-29634)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Fri, 19 Nov 2021 18:43:49 +0000 (12:43 -0600)
committerGitHub <noreply@github.com>
Fri, 19 Nov 2021 18:43:49 +0000 (19:43 +0100)
staticmethod() also became callable in Python 3.10.

See: b83861f02.

Doc/howto/descriptor.rst

index 575caeb720f3d0fa6f84580e7a449f768d50abe2..6ce062d0fa853e0d09f15f8b44f6b37c60cd5377 100644 (file)
@@ -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::