Practice · 1 of 2
Retry decorator factory
CHALLENGE
Difficulty: advanced+25 XP
Implement retry(times, exceptions=(Exception,)) — a decorator FACTORY that returns a decorator making fn retry up to times total attempts:
- only the given exception types trigger a retry; anything else propagates immediately
- if all attempts fail, re-raise the LAST exception
- preserve the function's metadata: wrapped.__name__ == fn.__name__
- track attempts for observability: expose wrapped.attempts (list of ints, one entry per call)
Press Submit to check your solution.
Back to lesson: Practice: Decorator Engineering