CPython's slice Implementation in C: Three Objects and a Bunch of Clamping
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’.
All posts published on this site.
Everything published here, newest first.
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’.
A CPython str picks the narrowest of 1, 2, or 4 bytes per code point at allocation time — so an all-ASCII string is one allocation with no UTF-8 cache at all.
A struct sequence is a tuple subclass whose hidden fields live past ob_size in the same allocation — so len() sees only the visible ones while attributes see everything.
super() is not special syntax — it’s a three-pointer C object, and the compiler even skips building one for super().attr via the LOAD_SUPER_ATTR bytecode.
t-strings produce a Template object — literal strings plus Interpolation objects — not a formatted string, so the pieces stay inspectable and reusable.