CPython's range Implementation in C: Lazy Sequences That Never Materialize
range holds four PyObject pointers and nothing else — the numbers are computed on demand, so range(10**18) costs the same as range(3).
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.
A slice is just three PyObject pointers — but turning them into real indices takes two clamping passes, and None becomes a sentinel meaning ‘use the extreme bound’.