The Magic of Self: How Python Inserts self Into Methods
summary
Shows working Python code that builds a Guitar class, a standalone play_note function and a custom Favorite descriptor that returns True for one instance and False for another, proving that functions are descriptors and Python’s function.__get__ creates a bound method. Explains the descriptor protocol’s three hooks (__get__, __set__, __delete__), contrasts property/classmethod/staticmethod behavior, and traces how CPython inserts the instance at attribute lookup time by combining function and instance into a callable.
AI-written summary · about
chapters (12)
- 0:00Introduction to self
- 1:21The guitar class example
- 4:40Speaker introduction
- 4:54Debunking self misconceptions
- 9:30Classes and function objects
- 12:21Accessing class attributes
- 15:05The descriptor protocol
- 17:11Implementing a custom descriptor
- 21:34How functions use descriptors
- 23:10Built-in descriptors
- 23:58Summary and resources
- 24:54Epilogue and closing
related talks
26mThe Magic of Self How Python inserts self into methods
25mThe magic of "self": How Python inserts "self" into methods.
25mThe Magic of Python
30mThe Wizardry of Metaprogramming
47mA Deep-Dive Into Python Classes
45mDescriptors made easy
38mUnderstanding attributes (Or: They're not nearly as boring as you think!)
22mLearning Parseltongue: Wizardry in Python
