Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve typing in on_exception #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions backoff/_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import asyncio
import logging
import operator
from typing import Any, Callable, Iterable, Optional, Type, Union
from typing import Any, Callable, Iterable, Optional, Type, TypeVar, Union

from backoff._common import (
_prepare_logger,
Expand Down Expand Up @@ -119,14 +119,15 @@ def decorate(target):
# Return a function which decorates a target with a retry loop.
return decorate

ET = TypeVar("ET", bound=Exception)

def on_exception(wait_gen: _WaitGenerator,
exception: _MaybeSequence[Type[Exception]],
exception: _MaybeSequence[Type[ET]],
*,
max_tries: Optional[_MaybeCallable[int]] = None,
max_time: Optional[_MaybeCallable[float]] = None,
jitter: Union[_Jitterer, None] = full_jitter,
giveup: _Predicate[Exception] = lambda e: False,
giveup: _Predicate[ET] = lambda e: False,
on_success: Union[_Handler, Iterable[_Handler], None] = None,
on_backoff: Union[_Handler, Iterable[_Handler], None] = None,
on_giveup: Union[_Handler, Iterable[_Handler], None] = None,
Expand Down