Designing with descriptors
Many uses of descriptors are already part of Python. We don't need to reinvent properties, class methods, or static methods.
The most compelling cases for creating new descriptors relate to mapping between Python objects and other software outside Python. Object-relational database mapping, for example, requires a great deal of care to ensure that a Python class has the right attributes in the right order to match a SQL table and columns. Also, when mapping to something outside Python, a descriptor class can handle the encoding and decoding of data, or fetching the data from external sources.
When building a web service client, we might consider using descriptors to make web service requests. The __get__() method, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access