Skip to content

Commit

Permalink
bpo-43917: Fix pure python equivalent for classmethod (GH-25544) (GH-…
Browse files Browse the repository at this point in the history
…25546)

Reported by Yahor Harunovich.
(cherry picked from commit 14092b5)
  • Loading branch information
miss-islington committed Apr 23, 2021
1 parent bc5a1a7 commit 34be484
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Doc/howto/descriptor.rst
Expand Up @@ -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)

Expand All @@ -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:

Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion Misc/ACKS
Expand Up @@ -380,7 +380,7 @@ Brian Curtin
Jason Curtis
Hakan Celik
Paul Dagnelie
Florian Dahlitz
Florian Dahlitz
Lisandro Dalcin
Darren Dale
Andrew Dalke
Expand Down Expand Up @@ -684,6 +684,7 @@ Michael Haubenwallner
Janko Hauser
Flavian Hautbois
Rycharde Hawkes
Yahor Harunovich
Ben Hayden
Jochen Hayek
Tim Heaney
Expand Down

0 comments on commit 34be484

Please sign in to comment.