© Jacob Zimmerman 2018
Jacob ZimmermanPython Descriptorshttps://doi.org/10.1007/978-1-4842-3727-4_5

5. Attribute Access and Descriptors

Jacob Zimmerman1 
(1)
New York, USA
 

It was stated earlier that attribute access calls are transformed into descriptor calls, but it was not stated how. The quick answer is that __getattribute__(), __setattr__(), and __delattr__() do it. That probably isn’t much of an answer for you, so I’ll dig into it more. These three methods exist on all normal objects, inherited via the object class (and classes inherit it from the type metaclass). As you might imagine, these methods are called when an attribute on an object is retrieved, set, or deleted, respectively, and it is these methods that decide whether to use a descriptor, ...

Get Python Descriptors: Understanding and Using the Descriptor Protocol 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.