Descriptors made easy
summary
Live coding shows Python descriptors implemented with __get__ and __set__ to replace property behavior: a Person.name descriptor computes first+last on access, assignment hooks run via __set__, and prints confirm the instance is passed in. A single class implements R/G/B by storing a position and slicing the hex string (single descriptor for R/G/B). A read‑only descriptor uses __set_name__ notified attribute name to save the assigned name and raise on set. Functions-as-descriptors (methods/properties) and all demos run successfully.
AI-written summary · about
chapters (8)
- 0:00Introduction to descriptors
- 5:25What is a descriptor
- 13:41Descriptors vs properties
- 21:21RGB color descriptor demo
- 27:53Read-only descriptor design
- 33:57Using __set_name__
- 40:03Descriptors in Python methods
- 41:51Q&A and conclusion
related talks
26mThe Magic of Self: How Python Inserts self Into Methods
26mThe Magic of Self How Python inserts self into methods
38mUnderstanding attributes (Or: They're not nearly as boring as you think!)
25mThe magic of "self": How Python inserts "self" into methods.
31mDescriptors: attribute access redefined
31mLife Under the A Guide to Python's Internal Conventions
47mA Deep-Dive Into Python Classes
25mAdvanced Python
