Descriptors: attribute access redefined
summary
Descriptors replace or augment default attribute access and are shown implemented as reusable objects: a type-constraint descriptor that type-checks on set and stores per-instance data in a weakref.WeakKeyDictionary (or alternatively in an instance __elk_attrs keyed by id), non-data versus data behavior, and that one descriptor instance is shared by all class instances. A working Elk object system (inspired by Moose) uses descriptors plus metaclasses to supply lazy init required attrs validation and generated constructors; performance is unexplored.
AI-written summary · about
chapters (13)
- 0:00Start
- 0:52Motivation
- 2:30Descriptors in standard library
- 3:31Descriptor protocol
- 4:38Example: type constraints
- 9:56Example: classmethod
- 12:16Implementation: when keys collide
- 13:41Implementation: storing values
- 15:09Descriptors and metaclasses
- 18:14Elk - example
- 20:12Elk - ElkAttribute
- 25:16Summary
- 25:59Resources
related talks
45mDescriptors made easy
38mUnderstanding attributes (Or: They're not nearly as boring as you think!)
30mMetaclasses Demystified
26mEverything you need to know but were afraid to ask about Data Classes
31mLife Under the A Guide to Python's Internal Conventions
30mThe Wizardry of Metaprogramming
47mA Deep-Dive Into Python Classes
24m"A Confession of My Python Sins"
