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)
def cm(cls, x, y):
return (cls, x, y)
+ @ClassMethod
+ @property
+ def __doc__(cls):
+ return f'A doc for {cls.__name__!r}'
+
+
.. doctest::
:hide:
>>> 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: