Step 3 / Select topic Python Hard

What this bank covers

  • C3 linearization
  • asyncio concurrency model
  • functools.lru_cache
  • The GIL
  • Small integer interning
  • __getattr__ vs __getattribute__
  • Assignment expressions (PEP 572)
  • Metaclass instantiation order
  • Generators as coroutines
  • __slots__
  • GIL release around blocking calls
  • multiprocessing sidesteps the GIL
  • __slots__ only helps end to end
  • __weakref__ must be an explicit slot
  • Metaclass __call__ intercepts instantiation
  • type() as a dynamic class factory
  • __init_subclass__ hook
  • __set_name__
  • The descriptor protocol
  • Data descriptors override instance __dict__
  • property as a descriptor
  • Non-data descriptors lose to instance __dict__
  • Cooperative super() calls
  • How bare super() finds its class
  • __new__ owns construction of immutables
  • __init__ only runs for matching types
  • Singleton via __new__
  • Dead weak references return None
  • WeakValueDictionary as a non-owning cache
  • Cyclic garbage collector
  • Generational garbage collection
  • __del__ and cyclic collection
  • __class_getitem__ for subscriptable classes
  • Lock vs RLock reentrancy
  • Task cancellation semantics
  • Single-dispatch generic functions
  • functools.cache
  • Coroutine objects are lazy
  • Blocking calls stall the whole event loop
  • asyncio.sleep(0) as a cooperative yield
  • Async generators
  • Locks still matter in cooperative concurrency
  • await as sugar over yield from
  • Generator return values
  • contextvars for per-task state
  • The GIL protects bytecode instructions, not statements
  • String literal interning
  • Explicit interning
  • Explicit GIL release in C extensions
  • Floats are not interned
  • ExceptionGroup and except*
  • The __prepare__ hook
  • fork vs spawn start methods
  • Overriding __eq__ nukes the default __hash__
  • The hash-invariance contract
  • sys.exc_info() outside exception handling
  • Virtual subclassing
  • Structural ABCs via __subclasshook__
  • Iterators are their own __iter__
  • cached_property needs an instance __dict__
  • Making objects callable
  • The __getattribute__ recursion trap
  • Immutable C-level types resist monkeypatching
  • autospec catches signature drift
  • Instance-level vs class-level patching scope
  • sys.setrecursionlimit
  • No tail-call optimization in CPython
  • memoryview and the buffer protocol
  • The bytes-like type family
  • Customizing pickling with __reduce__
  • Customizing deepcopy
  • The memo dict prevents infinite recursion
  • multiprocessing needs picklable targets
  • Explicit shared memory for multiprocessing
  • Exact __exit__ suppression semantics
  • contextlib.suppress
  • __index__ vs __int__
  • __exit__ is not called if __enter__ fails
  • finally always runs
  • __subclasses__() and weak tracking
  • finally exceptions override in-flight ones
  • The __format__ protocol
  • Mutable class attributes are shared state
  • Metaclass conflicts
  • Stacking @property with @abstractmethod
  • The reflected operator fallback protocol
  • NotImplemented lets the other side try
  • contextlib.ExitStack for dynamic context managers
  • Enum value aliasing
  • dataclass frozen + hash generation
  • Dataclasses reject mutable defaults outright
  • array module vs list memory layout
  • Double-underscore name mangling
  • getrefcount includes its own temporary reference
  • id() uniqueness only holds for live objects
  • match/case pattern specificity and ordering
  • Iterators cannot be rewound
  • gc.freeze() and copy-on-write friendliness
  • Truthiness fallback chain
  • staticmethod and classmethod as descriptors
  • Late-binding closures
  • Iterators can be consumed only once
  • Sort keys instead of comparison functions
  • Building bytes: join versus +=