CPython's LazyImport Implementation in C
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.
All posts published on this site.
Everything published here, newest first.
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.
None is a single static immortal PyObject: no allocation, no refcounting, and identity comparison — plus a dedicated stack-ref encoding for the eval loop.