CPython's tuple Implementation in C: Immutable, Inline, and Recycled
A CPython tuple has no separate buffer — the item array is embedded in the object, so its memory footprint is exactly its length and nothing more.
All posts published on this site.
Everything published here, newest first.
A CPython tuple has no separate buffer — the item array is embedded in the object, so its memory footprint is exactly its length and nothing more.
A Python class is a C struct full of function pointers — tp_dealloc, tp_getattro, tp_new — and PyType_Ready is what fills in the blanks it inherits from the base.
types.GenericAlias is a five-field C struct wrapping an origin and a tuple of args, with parameters computed lazily and cached under a critical section.
Typing’s core objects are now C structs with lazily-evaluated bounds and defaults — an evaluate_* callable is resolved and cached the first time you read it.
A union owns its arguments: it dedups them with a set, flattens nested unions, normalizes None to NoneType, and collapses a one-member union back to that member.