16. Short Q&A Prompts

Practice prompts to sharpen depth and articulation under time pressure.

  • Describe the iterator protocol and how a generator satisfies it. When would you use yield from?

  • Show a context manager built with @contextmanager and contrast with a class-based CM.

  • Write a small decorator that preserves metadata with functools.wraps.

  • Explain dataclass(slots=True, frozen=True) trade-offs.

  • Demonstrate match/case with a mapping pattern and a guard (if ...).

  • Pick between threads, processes, and asyncio for a given workload and justify.

  • Avoid N+1 in SQLAlchemy: selectinload vs joinedload — when each?

  • pytest fixtures: scope and parametrization examples.

  • Design idempotent POST with Idempotency-Key.

  • Prevent a cache stampede: outline lock/jitter/refresh-ahead.

  • Show asyncio.Semaphore to cap concurrency.

  • Implement optimistic locking with a version column.

  • Use pytest monkeypatch to override an env var.

  • Explain ExceptionGroup and handle with except*.

  • Add ETag-based conditional GET to a REST endpoint.