Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumPythondecorators with argumentsSingle-choice MCQ

A decorator is written so it can be used both as `@trace` and as `@trace(label='X')`. What makes the no-parentheses form work?

import functools def trace(fn=None, *, label='call'): if fn is None: return functools.partial(trace, label=label) @functools.wraps(fn) def w(*a, **k): return f"{label}:{fn(*a, **k)}" return w