@decorator and Decorator Arguments

Scenario: One retry wrapper needs a configurable attempt count.

New words, in plain English

@logged means func = logged(func). A configurable decorator adds an outer factory level. Trace the layers slowly: configuration, function, then call arguments.

Analogy: A Python program is like a clear set of instructions for a careful helper: names label things, indentation groups steps, and errors explain where the helper became confused.

A small, real example

def repeat(times):
    def decorate(func):
        def wrapper(*args, **kwargs):
            return [func(*args, **kwargs) for _ in range(times)]
        return wrapper
    return decorate

@repeat(3)
def ping(): return "pong"
Tip: Prefer a plain helper when decorator nesting makes control flow harder to understand.
Goal: Practice this idea in the py-decorators challenge at /labs/python. Fix the broken program, run it yourself, then use check to prove the real end state.