Skip to content
Opensource internals
  • Posts

Python

CPython's range Implementation in C: Lazy Sequences That Never Materialize

Oct 20, 2026 7 min read Jay Hubbert

range holds four PyObject pointers and nothing else — the numbers are computed on demand, so range(10**18) costs the same as range(3).

PythonCpythonInternalsRange

Read more →

CPython's Sentinel Implementation in C: Unique Marker Objects for Defaults

Oct 20, 2026 8 min read Jay Hubbert

Each sentinel() call allocates a distinct, GC-tracked object that infers its module from the calling frame — which is exactly what makes it picklable.

PythonCpythonInternalsSentinel

Read more →

CPython's set and frozenset Implementation in C: One Hash Table, Two Flavors

Oct 20, 2026 9 min read Jay Hubbert

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.

PythonCpythonInternalsSet

Read more →

CPython's SimpleNamespace Implementation in C

Oct 20, 2026 7 min read Jay Hubbert

SimpleNamespace is a PyObject_HEAD plus a single dict pointer — tp_dictoffset points right at it, so attribute access is just dict lookup.

PythonCpythonInternalsNamespace

Read more →

CPython's slice Implementation in C: Three Objects and a Bunch of Clamping

Oct 20, 2026 9 min read Jay Hubbert

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’.

PythonCpythonInternalsSlice

Read more →

← Newer Page 7 of 11 Older →

© 2026 Jay Hubbert · Built with Hugo 0.168.0

RSS ·