CPython's type Implementation in C (the Metaclass): How Classes Are Objects
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.
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.
A weak reference points at an object without owning it — so reading it requires trying to incref the target under a lock, and failing means the target is gone.