Hard Python Topics
Descriptors, MRO, metaclasses, memory, the GIL, performance and architecture.
Descriptors and attribute access
Functions, properties and many ORM fields use the descriptor protocol: __get__, __set__ and __delete__. Learn it when building frameworks, not as a default application pattern.
MRO and multiple inheritance
Python uses a method resolution order to decide which implementation runs. Inspect ClassName.__mro__ and use cooperative super() consistently. Prefer composition when relationships become difficult to explain.
Metaclasses
A metaclass controls class creation. Frameworks use them for registration and validation, but decorators and __init_subclass__ are usually easier to maintain.
Memory and the GIL
CPython primarily uses reference counting with a cycle collector. The GIL allows one thread to execute Python bytecode at a time in a process. Threads are useful for blocking I/O, async for many coordinated I/O tasks, and processes or native code for CPU-heavy parallel work.
Performance workflow
- Measure with realistic data.
- Profile to find the actual bottleneck.
- Improve the algorithm or data structure first.
- Reduce I/O and allocations.
- Measure again and keep regression tests.
Architecture
Keep domain rules independent from web, CLI and storage frameworks. Make side effects explicit, define boundaries and design retries around idempotency.