Advanced Python
Dive deep — metaclasses, descriptors, ABCs, protocols, and CPython internals.
Metaclasses
A metaclass is the class of a class — it controls how classes are created. `type...
Descriptors
A descriptor is an object that defines `__get__`, `__set__`, or `__delete__`. Wh...
Abstract Base Classes (ABCs)
`abc.ABC` (or `metaclass=abc.ABCMeta`) lets you define interfaces that subclasse...
Protocols (PEP 544) — Structural Subtyping
`typing.Protocol` (Python 3.8+) defines structural interfaces — any class that i...
`__slots__` — Memory Optimization
By default, Python stores instance attributes in a `__dict__` per instance — fle...
Memory Management and the `gc` Module
CPython uses reference counting as its primary GC mechanism — an object is freed...
CPython Internals — Bytecode and `dis`
CPython compiles Python source to bytecode (`.pyc` files), which the CPython vir...
The Import System
`import` triggers a multi-step process: find the module (using `sys.meta_path` f...
Type Narrowing and `TypeGuard`
Type narrowing is the process by which a type checker infers a more specific typ...
Performance Profiling
`cProfile` is CPython's built-in deterministic profiler — it records every funct...