GH-91095: Specialize calls to normal python classes by markshannon · Pull Request #93221 · python/cpython
I get the rough idea of this, and to save some time for the other reviewers, here's how it goes:
Frames before a Python class instantiation
__main__ -> NULL
Frames when a Python class is instantiated:
__main__ -> shim -> __init__ -> NULL
(Shim is responsible for replacing None returned by __init__ with self. It contains a special instruction EXIT_INIT_CHECK to verify the None.)
I'm not confident that I can catch any subtle errors with this much code. Let's test this with buildbots.