A Deep-Dive Into Python Classes
summary
Deep dive into Python's object model covers __new__/__init__/__del__ lifecycle, garbage collection quirks with circular references and gc.collect, and concrete benchmarks showing slots save about 6x memory (million objects × 16 attrs) with only ~10% speed change. Explains descriptors and property implementation, how functions become bound methods via the descriptor protocol (method = descriptor binding), getattr/__getattribute__ lookup order, abstract base classes in collections, and practical patterns like storing instance state in parallel lists.
AI-written summary · about
chapters (25)
- 0:00Start
- 3:13Objects in PERL
- 7:01What is a Class?
- 8:13Instance Lifecycle
- 15:50_slots__ Memory
- 16:20Obtaining Attributes
- 17:05A Diamond Inheritance
- 18:06Resolution Order
- 19:29Inheritance Magic
- 20:59Virtual Subclasses
- 22:17Subclass Yourself
- 23:05Method Calling
- 23:44Methods in Classes & Instances
- 25:17Calling Methods
- 26:51Instances Don't Contain Methods
- 27:38Executing Code on Attribute Access
- 30:29Instance Methods Provided by the Descriptor
- 31:10Functions are Descriptors
- 32:09@property Decorator
- 32:42@property2 Definition
- 33:39@property2 Test
- 34:10Descriptor Protocol
- 35:51Tack On a Class Method
- 39:34Test Instance Method II
- 40:24Questions?
related talks
38mUnderstanding attributes (Or: They're not nearly as boring as you think!)
23mMemoirs of a Python Object: Memory Management and Improving Performance
01h 27mObjectionable Content
01h 10mIt's Pythons All The Way Down: Python Types & Metaclasses Made Simple
25mIs it me or Python memory management? 🤔💻
32mEasier Classes: Python Classes Without All the Cruft
23mPython Memory Understanding
31mPython Data Model
