Python Class Creation Runs a Defined Hook Sequence
The order of metaclass selection, namespace preparation, class-body execution, __set_name__, __init_subclass__, and decorators.
Python technical articles
Clear explanations of the details that shape real programs.
Explore Python language behavior, the standard library, concurrency, and object-model details that affect real programs.
15 articles
The order of metaclass selection, namespace preparation, class-body execution, __set_name__, __init_subclass__, and decorators.
How __slots__ creates member descriptors, removes automatic instance dictionaries, and affects subclasses and weak references.
How match and case handle sequence, mapping, class, capture, value, and guarded patterns in Python 3.10 and later.
Why closures created in loops share late-bound names, plus reliable capture patterns and nonlocal state.
How Python super() advances through the method resolution order and how to design cooperative multiple inheritance.
How generator creation, send, throw, close, and yield from cooperate across suspension points.
How task cancellation reaches coroutines, interacts with cleanup, and behaves under gather and TaskGroup.
A step-by-step model for data descriptors, instance dictionaries, methods, and attribute fallbacks.
How defaults, equality, ordering, frozen instances, and hashing interact in generated dataclass methods.
How with statements enter, unwind, suppress exceptions, and scale to dynamic resources with ExitStack.
How sys.modules, package initialization, from-import bindings, cycles, and reload shape import behaviour.
How structural subtyping, runtime-checkable protocols, generic variance, and explicit implementations fit together.
A practical model for function defaults, shallow copies, nested aliases, and defensive API boundaries.
What CPython's interpreter lock does, where it is released, and why shared-state invariants still need synchronization.
How ExceptionGroup and except-star split, handle, and reassemble multiple errors without flattening context.