Skip to content

Commit 34be484

Browse files
bpo-43917: Fix pure python equivalent for classmethod (GH-25544) (GH-25546)
Reported by Yahor Harunovich. (cherry picked from commit 14092b5)
1 parent bc5a1a7 commit 34be484

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
@@ -1319,7 +1319,7 @@ Using the non-data descriptor protocol, a pure Python version of
13191319
def __get__(self, obj, cls=None):
13201320
if cls is None:
13211321
cls = type(obj)
1322-
if hasattr(obj, '__get__'):
1322+
if hasattr(type(self.f), '__get__'):
13231323
return self.f.__get__(cls)
13241324
return MethodType(self.f, cls)
13251325

@@ -1332,6 +1332,12 @@ Using the non-data descriptor protocol, a pure Python version of
13321332
def cm(cls, x, y):
13331333
return (cls, x, y)
13341334

1335+
@ClassMethod
1336+
@property
1337+
def __doc__(cls):
1338+
return f'A doc for {cls.__name__!r}'
1339+
1340+
13351341
.. doctest::
13361342
:hide:
13371343

@@ -1343,6 +1349,11 @@ Using the non-data descriptor protocol, a pure Python version of
13431349
>>> t.cm(11, 22)
13441350
(<class 'T'>, 11, 22)
13451351

1352+
# Check the alternate path for chained descriptors
1353+
>>> T.__doc__
1354+
"A doc for 'T'"
1355+
1356+
13461357
The code path for ``hasattr(obj, '__get__')`` was added in Python 3.9 and
13471358
makes it possible for :func:`classmethod` to support chained decorators.
13481359
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
@@ -380,7 +380,7 @@ Brian Curtin
380380
Jason Curtis
381381
Hakan Celik
382382
Paul Dagnelie
383-
Florian Dahlitz
383+
Florian Dahlitz
384384
Lisandro Dalcin
385385
Darren Dale
386386
Andrew Dalke
@@ -684,6 +684,7 @@ Michael Haubenwallner
684684
Janko Hauser
685685
Flavian Hautbois
686686
Rycharde Hawkes
687+
Yahor Harunovich
687688
Ben Hayden
688689
Jochen Hayek
689690
Tim Heaney

0 commit comments

Comments
 (0)