]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43917: Fix pure python equivalent for classmethod (GH-25544) (GH-25546)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 23 Apr 2021 01:16:16 +0000 (18:16 -0700)
committerGitHub <noreply@github.com>
Fri, 23 Apr 2021 01:16:16 +0000 (18:16 -0700)
Reported by Yahor Harunovich.
(cherry picked from commit 14092b5a4ae4caf1c77f685450016a0d1ad0bd6c)

Doc/howto/descriptor.rst
Misc/ACKS

index 93dd35441f41c2c19682bb36156da888bbf3c342..eef6b2dfa00c261282bd15c709886d6cade49787 100644 (file)
@@ -1319,7 +1319,7 @@ Using the non-data descriptor protocol, a pure Python version of
         def __get__(self, obj, cls=None):
             if cls is None:
                 cls = type(obj)
-            if hasattr(obj, '__get__'):
+            if hasattr(type(self.f), '__get__'):
                 return self.f.__get__(cls)
             return MethodType(self.f, cls)
 
@@ -1332,6 +1332,12 @@ Using the non-data descriptor protocol, a pure Python version of
         def cm(cls, x, y):
             return (cls, x, y)
 
+        @ClassMethod
+        @property
+        def __doc__(cls):
+            return f'A doc for {cls.__name__!r}'
+
+
 .. doctest::
     :hide:
 
@@ -1343,6 +1349,11 @@ Using the non-data descriptor protocol, a pure Python version of
     >>> t.cm(11, 22)
     (<class 'T'>, 11, 22)
 
+    # Check the alternate path for chained descriptors
+    >>> T.__doc__
+    "A doc for 'T'"
+
+
 The code path for ``hasattr(obj, '__get__')`` was added in Python 3.9 and
 makes it possible for :func:`classmethod` to support chained decorators.
 For example, a classmethod and property could be chained together:
index 4f7c92c9dc0f6adeb5b8f5b524810888be624fb9..ee2f3fa2e3aa58096a795d7ca3a194e42c1da628 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -380,7 +380,7 @@ Brian Curtin
 Jason Curtis
 Hakan Celik
 Paul Dagnelie
-Florian Dahlitz 
+Florian Dahlitz
 Lisandro Dalcin
 Darren Dale
 Andrew Dalke
@@ -684,6 +684,7 @@ Michael Haubenwallner
 Janko Hauser
 Flavian Hautbois
 Rycharde Hawkes
+Yahor Harunovich
 Ben Hayden
 Jochen Hayek
 Tim Heaney