Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumPythoncustom context managersSingle-choice MCQ

A class-based context manager's `__exit__` is defined as below. What is the observable behavior?

class Guard: def __enter__(self): return self def __exit__(self, et, ev, tb): return et is ValueError with Guard(): raise ValueError("x") print("A") with Guard(): raise KeyError("y") print("B")