The Magic of Self How Python inserts self into methods
summary
Explains that the automatic first-argument insertion is not magic but the descriptor protocol, shows a hand‑written FavoriteDescriptor class implementing __get__ that returns True for a specific instance name, and demonstrates that normal functions are descriptors whose __get__ produces a bound method (a partial that prebinds the instance). Shows classmethod/staticmethod/property as wrapper descriptors, uses pseudo‑Python/C examples and a live instance/class demo proving the mechanism works.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 3:18Why do we have self
- 4:49About me
- 5:25Self in Python
- 10:31Object attributes
- 13:26Descriptor protocol
- 14:44Implement a simple descriptor
- 18:56Get method
- 21:02Other builtin descriptors
- 22:47Summary
- 23:39Recommendations
related talks
25mThe magic of "self": How Python inserts "self" into methods.
26mThe Magic of Self: How Python Inserts self Into Methods
25mThe Magic of Python
45mDescriptors made easy
30mThe Wizardry of Metaprogramming
38mUnderstanding attributes (Or: They're not nearly as boring as you think!)
47mA Deep-Dive Into Python Classes
01h 10mIt's Pythons All The Way Down: Python Types & Metaclasses Made Simple
