Attribute Descriptors

Descriptors are a way of resuing the same access logic in multiple attributes. For example, field types in ORM such as the DjangoORM and SQL Alchemy are descriptors, managing the flow of data from the fields in a database record to Python object attributes and vice versa.

A descriptor is a class that implements a protocol consisting of the __get__, __set__, and the __delete__ methods. The property class implements the full descriptor protocol. As usual with protocols, partial implementations are OK. In fact, most descriptors we see in real code implement only __get__ and __set__, and many implement only one of these methods.

end ...

原文地址:https://www.cnblogs.com/neozheng/p/12617124.html