Skip to content

Commit 14092b5

Browse files
authored
bpo-43917: Fix pure python equivalent for classmethod (pythonGH-25544)
Reported by Yahor Harunovich.
1 parent 6afb0a8 commit 14092b5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Doc/howto/descriptor.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ Using the non-data descriptor protocol, a pure Python version of
13291329
def __get__(self, obj, cls=None):
13301330
if cls is None:
13311331
cls = type(obj)
1332-
if hasattr(obj, '__get__'):
1332+
if hasattr(type(self.f), '__get__'):
13331333
return self.f.__get__(cls)
13341334
return MethodType(self.f, cls)
13351335

@@ -1342,6 +1342,12 @@ Using the non-data descriptor protocol, a pure Python version of
13421342
def cm(cls, x, y):
13431343
return (cls, x, y)
13441344

1345+
@ClassMethod
1346+
@property
1347+
def __doc__(cls):
1348+
return f'A doc for {cls.__name__!r}'
1349+
1350+
13451351
.. doctest::
13461352
:hide:
13471353

@@ -1353,6 +1359,11 @@ Using the non-data descriptor protocol, a pure Python version of
13531359
>>> t.cm(11, 22)
13541360
(<class 'T'>, 11, 22)
13551361

1362+
# Check the alternate path for chained descriptors
1363+
>>> T.__doc__
1364+
"A doc for 'T'"
1365+
1366+
13561367
The code path for ``hasattr(obj, '__get__')`` was added in Python 3.9 and
13571368
makes it possible for :func:`classmethod` to support chained decorators.
13581369
For example, a classmethod and property could be chained together:

Misc/ACKS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ Brian Curtin
388388
Jason Curtis
389389
Hakan Celik
390390
Paul Dagnelie
391-
Florian Dahlitz
391+
Florian Dahlitz
392392
Lisandro Dalcin
393393
Darren Dale
394394
Andrew Dalke
@@ -694,6 +694,7 @@ Michael Haubenwallner
694694
Janko Hauser
695695
Flavian Hautbois
696696
Rycharde Hawkes
697+
Yahor Harunovich
697698
Ben Hayden
698699
Jochen Hayek
699700
Tim Heaney

0 commit comments

Comments
 (0)