Built-in decorators for methods

As you might have known from looking at the official documentation (PYDESCR-02), all @property, @classmethod, and @staticmethod decorators are descriptors.

We have mentioned several times that the idiom makes the descriptor return itself when it's being called from a class directly. Since properties are actually descriptors, that is the reason why, when we ask it from the class, we don't get the result of computing the property, but the entire property object instead:

>>> class MyClass:... @property... def prop(self): pass...>>> MyClass.prop<property object at 0x...>

For class methods, the __get__ function in the descriptor will make sure that the class is the first parameter to be passed to the function being ...

Get Clean Code in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.