The Craziest fn Thing I've Ever Seen (and It Lives in CPython!!!)
summary
Digs into CPython dataclasses and finds _create_fn, a generator that composes a name, args and body into source text and execs it into locals to synthesize real methods (used to build __init__, wrappers and the frozen-instance __setattr__/__delattr__ behavior). Demonstrates constructing add_two_numbers at runtime, seeing the function appear in locals and calling it successfully, and credits Eric V. Smith et al while highlighting practical metaprogramming and decorator machinery.
AI-written summary · about
chapters (8)
- 0:00Intro
- 0:14What are Data Classes
- 1:01What are Data Classes in Kotlin
- 2:03The Problem
- 3:10The Function
- 3:53Adding Two Numbers
- 4:34Extra Fun
- 4:58Conclusion








