Loading topic
obj.name does, you need to know where Python keeps the values that lookup searches. This chapter covers the two main places, the instance __dict__ and the class __dict__. It also covers what goes in each one and why writing behaves differently from reading. Later cha5 min read__dict__ and the class __dict__. This chapter covers how Python searches the class side when a name is not found on the class itself. I assume you can write classes with inheritance, know that super() exists, and have used dunder6 min read__dict__, and have seen dunder methods such as __init__. The previous chapters covered where attributes are stored and how the MRO orders the class hierarchy. This chapter covers the code that performs the se5 min read__dict__, the MRO, and object.__getattribute__. Here we define the protocol itself. The next chapter cover4 min read__dict__ namespaces work, how the MRO is searched, and that obj.name goes through object.__getattribute__. It also assumes you know the three descriptor methods: __get__, __set__ and __delete__. Here you will learn the one rule that de4 min read__dict__, the method resolution order (MRO), and the descriptor protocol with data and non-data descriptors. Here we combine those pieces into one ordered procedure and test it against edge cases.4 min read__get__, __set__, __delete__). You should also know that a data descriptor, one that defines __set__ or __delete__, beats the instance __dict__ during lookup. This chapter covers the practical question of where a descriptor keeps its value4 min read__get__, __set__ and the split between data and non-data descriptors. Here we apply those ideas to the most common descriptor in Python: the plain f5 min read__get__, __set__, __delete__) and the difference between data and non-data descriptors. It also assumes you know the lookup order of object.__getattribute__. Here you use that machinery to see that property is an ordinary class built o4 min read__get__, __set__, __delete__), the difference between data and non-data descriptors, and how functions become bound methods. Earlier chapters cover each of these. Here you will see that classmethod and staticmethod are small non-data d4 min readobject.__getattribute__ walks the lookup order: data descriptor, instance __dict__, then non-data descriptor or class attribute. Here we cover what happens when every step of that order comes up empty, and the cases where it fires when you did not expect it.4 min read__get__, __set__, __delete__), the data versus non-data distinction, and the full lookup order from earlier chapters. __slots__ is a feature of the class statement that uses that machinery to change where instance attributes are stored.5 min readobj.name is resolved. That means the data versus non-data descriptor rules, the instance __dict__, and __set_name__. It uses those rules to explain functools.cached_property. This one feature shows why the "non-data" half of the descriptor split exists.5 min read__dict__, then non-data descriptor or plain class attribute, then __getattr__. It also assumes you are comfortable with the MRO (method resolution order) and have seen a metaclass d5 min read__set_name__, and property. It collects the mistakes that come up most often when you write or use descriptors, and the tools for finding out why an attribute behaves the way it does.4 min read