CPython's PyCapsule Implementation in C: A void* Wrapper for Extension Modules
A PyCapsule is a typed, name-checked void* wrapper: the name stops you reading the wrong capsule, and the destructor gets one shot to clean up before the memory goes.
All posts published on this site.
Everything published here, newest first.
A PyCapsule is a typed, name-checked void* wrapper: the name stops you reading the wrong capsule, and the destructor gets one shot to clean up before the memory goes.
range holds four PyObject pointers and nothing else — the numbers are computed on demand, so range(10**18) costs the same as range(3).
Each sentinel() call allocates a distinct, GC-tracked object that infers its module from the calling frame — which is exactly what makes it picklable.
CPython’s set is an open-addressing hash table with three slot states — unused, dummy, active — and dummies are what keep deleted keys from breaking probe chains.
SimpleNamespace is a PyObject_HEAD plus a single dict pointer — tp_dictoffset points right at it, so attribute access is just dict lookup.