mirror of
https://github.com/python/cpython.git
synced 2025-09-29 11:45:57 +00:00
bpo-43917: Fix pure python equivalent for classmethod (GH-25544) (GH-25546)
Reported by Yahor Harunovich.
(cherry picked from commit 14092b5a4a
)
This commit is contained in:
parent
bc5a1a7adf
commit
34be48450f
2 changed files with 14 additions and 2 deletions
|
@ -1319,7 +1319,7 @@ Using the non-data descriptor protocol, a pure Python version of
|
||||||
def __get__(self, obj, cls=None):
|
def __get__(self, obj, cls=None):
|
||||||
if cls is None:
|
if cls is None:
|
||||||
cls = type(obj)
|
cls = type(obj)
|
||||||
if hasattr(obj, '__get__'):
|
if hasattr(type(self.f), '__get__'):
|
||||||
return self.f.__get__(cls)
|
return self.f.__get__(cls)
|
||||||
return MethodType(self.f, 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):
|
def cm(cls, x, y):
|
||||||
return (cls, x, y)
|
return (cls, x, y)
|
||||||
|
|
||||||
|
@ClassMethod
|
||||||
|
@property
|
||||||
|
def __doc__(cls):
|
||||||
|
return f'A doc for {cls.__name__!r}'
|
||||||
|
|
||||||
|
|
||||||
.. doctest::
|
.. doctest::
|
||||||
:hide:
|
:hide:
|
||||||
|
|
||||||
|
@ -1343,6 +1349,11 @@ Using the non-data descriptor protocol, a pure Python version of
|
||||||
>>> t.cm(11, 22)
|
>>> t.cm(11, 22)
|
||||||
(<class 'T'>, 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
|
The code path for ``hasattr(obj, '__get__')`` was added in Python 3.9 and
|
||||||
makes it possible for :func:`classmethod` to support chained decorators.
|
makes it possible for :func:`classmethod` to support chained decorators.
|
||||||
For example, a classmethod and property could be chained together:
|
For example, a classmethod and property could be chained together:
|
||||||
|
|
|
@ -380,7 +380,7 @@ Brian Curtin
|
||||||
Jason Curtis
|
Jason Curtis
|
||||||
Hakan Celik
|
Hakan Celik
|
||||||
Paul Dagnelie
|
Paul Dagnelie
|
||||||
Florian Dahlitz
|
Florian Dahlitz
|
||||||
Lisandro Dalcin
|
Lisandro Dalcin
|
||||||
Darren Dale
|
Darren Dale
|
||||||
Andrew Dalke
|
Andrew Dalke
|
||||||
|
@ -684,6 +684,7 @@ Michael Haubenwallner
|
||||||
Janko Hauser
|
Janko Hauser
|
||||||
Flavian Hautbois
|
Flavian Hautbois
|
||||||
Rycharde Hawkes
|
Rycharde Hawkes
|
||||||
|
Yahor Harunovich
|
||||||
Ben Hayden
|
Ben Hayden
|
||||||
Jochen Hayek
|
Jochen Hayek
|
||||||
Tim Heaney
|
Tim Heaney
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue