Hudson River Trading · CS Fundamentals
Python Language and Runtime Fundamentals
TrueInterview
October 7, 2026 · 2 min read
Python Language and Runtime Essentials
Clarifying Questions to Ask
- Should responses target CPython specifically, or Python language semantics as they apply across implementations?
- Are brief code snippets acceptable, and which Python version should be assumed?
Part 1: Decorators
Describe what a Python decorator is, how the @decorator syntax gets evaluated, and how you would implement a parameterized function decorator while keeping the wrapped function's metadata intact.
Candidate hint: Rewrite the @ syntax as the assignment it stands for before talking about use cases.
What This Part Should Cover
- When decoration happens and how the callable is transformed
- Using closures to hold decorator arguments
- Preserving metadata and typical state or binding pitfalls
Part 2: Dictionaries, Hashability, and Collisions
Give a high-level account of how a Python dictionary locates a key and handles hash collisions. Then explain how to make a user-defined class safely hashable, and why a list cannot serve as a dictionary key. Candidate hint: Connect the answer to the equality/hash stability contract, rather than just to which built-in types are mutable.
What This Part Should Cover
- Hash lookup, equality checks, and collision resolution
- The equality/hash contract and the risk from mutation
- Choosing the right class behavior, including when a class should stay unhashable
Part 3: Generators
Explain generators, yield, lazy iteration, and how a generator function differs from an ordinary function. Include how state and exceptions behave across iterations.
Candidate hint: Describe what the generator function returns when called, before its body has run to the first yield.
What This Part Should Cover
- Iterator protocol and suspended execution state
- Memory and streaming advantages
- Exhaustion,
StopIteration, and cleanup concerns
Part 4: Single and Double Star Syntax
Explain what * and ** mean in function definitions, function calls, assignment unpacking, and collection literals. Identify at least one ordering or duplicate-key error.
Candidate hint: Keep collection packing/unpacking distinct from keyword-only and positional-only call semantics.
What This Part Should Cover
*args,**kwargs, and unpacking at the call site- Extended iterable unpacking and mapping expansion
- Signature boundaries and collision behavior
Part 5: Garbage Collection
Explain Python memory management and garbage collection, noting the relevant implementation caveats. Include reference counting, cyclic garbage, finalization, and why object reclamation should not be treated as deterministic, portable resource cleanup. Candidate hint: Separate language guarantees from common CPython behavior.
What This Part Should Cover
- Reference ownership and cycle detection
- Finalizers, weak references, and implementation differences
- Context managers for external resources
What a Strong Answer Covers
- Accurate language semantics, with CPython-specific details clearly marked
- Short examples that reveal edge cases instead of hiding them
- Invariants such as stable hashing and one-pass generator exhaustion
- Practical consequences for API design, debugging, and resource safety
Follow-up Questions
- How does decorating an instance method interact with the descriptor protocol?
- What can go wrong when an object's hash depends on a mutable field?
- When might a generator expression be slower or harder to read than a list comprehension?
- Why can relying on
__del__make cycle handling and shutdown behavior difficult?
Overview: Review core Python semantics through decorators, dictionary hashing, generators, unpacking syntax, and memory management. Separate language guarantees from CPython behavior while connecting edge cases to API design, debugging, and safe resource cleanup.