[Python-checkins] bpo-43917: Fix pure python equivalent for classmethod (GH-25544)
rhettinger
webhook-mailer at python.org
Thu Apr 22 20:53:44 EDT 2021
https://github.com/python/cpython/commit/14092b5a4ae4caf1c77f685450016a0d1ad0bd6c
commit: 14092b5a4ae4caf1c77f685450016a0d1ad0bd6c
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2021-04-22T17:53:36-07:00
summary:
bpo-43917: Fix pure python equivalent for classmethod (GH-25544)
Reported by Yahor Harunovich.
files:
M Doc/howto/descriptor.rst
M Misc/ACKS
diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst
index bf026f4b7e61be..074591ff54fb8d 100644
--- a/Doc/howto/descriptor.rst
+++ b/Doc/howto/descriptor.rst
@@ -1329,7 +1329,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)
@@ -1342,6 +1342,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:
@@ -1353,6 +1359,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:
diff --git a/Misc/ACKS b/Misc/ACKS
index e394ea6802fbe2..760d6c79835f87 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -388,7 +388,7 @@ Brian Curtin
Jason Curtis
Hakan Celik
Paul Dagnelie
-Florian Dahlitz
+Florian Dahlitz
Lisandro Dalcin
Darren Dale
Andrew Dalke
@@ -694,6 +694,7 @@ Michael Haubenwallner
Janko Hauser
Flavian Hautbois
Rycharde Hawkes
+Yahor Harunovich
Ben Hayden
Jochen Hayek
Tim Heaney
More information about the Python-checkins
mailing list