Practice ยท 1 of 2
Retry decorator factory
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)
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Decorator Engineering