From 27a021b6cc70987e4800d1f23fe726e3c193e9d8 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 19 Nov 2021 00:34:46 -0600 Subject: [PATCH 1/2] bpo-19072: Classmethod can wrap other classmethod like descriptors. See b83861f02 --- Doc/howto/descriptor.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst index 575caeb720f3d0..4252ca7021c8b7 100644 --- a/Doc/howto/descriptor.rst +++ b/Doc/howto/descriptor.rst @@ -1344,7 +1344,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:: From f62b2b16042256b5c47c76510184c9612593da94 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 19 Nov 2021 01:49:31 -0600 Subject: [PATCH 2/2] staticmethod() became callable in Python 3.10 --- Doc/howto/descriptor.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst index 4252ca7021c8b7..6ce062d0fa853e 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