CPython's Iterator Implementation in C
A for loop compiles to PyObject_GetIter plus repeated tp_iternext calls — two C function pointers, no Python-level dispatch for built-in types.
All posts published on this site.
Everything published here, newest first.
A for loop compiles to PyObject_GetIter plus repeated tp_iternext calls — two C function pointers, no Python-level dispatch for built-in types.
Lazy imports work by parking a proxy object in the namespace and atomically replacing it with the real module the first time the name is touched.
CPython’s list is a contiguous array of pointers with a separate size and capacity, growing by about an eighth each time so appends stay O(1) amortized.
CPython splits memoryview into a shared managed-buffer snapshot and a per-view copy of shape/strides, so slicing adjusts pointers instead of copying data.
A Python module is a PyModuleObject with a dict as its namespace, plus optional per-module C state — and its tp_getattro is where lazy imports get resolved.