Skip to content
Sharp

Advanced Python · interview question

A bug appears around contextlib helpers. What is the strongest first debugging move?

Multiple choiceMediumchapter-14-curatedpremiumadvanced-pythoncontextlib-helpers
python
from contextlib import contextmanager

@contextmanager
def audit_scope(name: str):
    print(f"start:{name}")
    try:
        yield
    finally:
        print(f"finish:{name}")
Choose one answer
Answer and explanation

Correct answer

D. Trace one concrete example, inspect the state transitions, and compare them to the intended rule before rewriting anything.

Why

That approach is reliable because it creates evidence. Not every scope needs a full class; over-engineering the mechanism can distract from the real rule.

Test yourself on Advanced Python

A free test with instant, explained results. No account needed.

Start free test
All Advanced Python questions →