Skip to content

Commit 4c767be

Browse files
Apply the Ruff FA rules (#104)
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
1 parent 3c208fc commit 4c767be

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
- Apply the Ruff `B` rules [#100](https://github.com/python-backoff/backoff/pull/100) (from [@edgarrmondragon](https://github.com/edgarrmondragon))
1212

13+
- Apply the Ruff `FA` rules [#104](https://github.com/python-backoff/backoff/pull/104) (from [@edgarrmondragon](https://github.com/edgarrmondragon))
14+
1315
## [v2.3.1] - 2025-12-18
1416

1517
### Fixed

backoff/_decorator.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from __future__ import annotations
2+
13
import inspect
24
import logging
35
import operator
4-
from typing import Any, Callable, Iterable, Optional, Type, Union
6+
from typing import TYPE_CHECKING, Any, Callable, Iterable
57

68
from backoff import _async, _sync
79
from backoff._common import (
@@ -11,28 +13,30 @@
1113
_prepare_logger,
1214
)
1315
from backoff._jitter import full_jitter
14-
from backoff._typing import (
15-
_CallableT,
16-
_Handler,
17-
_Jitterer,
18-
_MaybeCallable,
19-
_MaybeLogger,
20-
_MaybeSequence,
21-
_Predicate,
22-
_WaitGenerator,
23-
)
16+
17+
if TYPE_CHECKING:
18+
from backoff._typing import (
19+
_CallableT,
20+
_Handler,
21+
_Jitterer,
22+
_MaybeCallable,
23+
_MaybeLogger,
24+
_MaybeSequence,
25+
_Predicate,
26+
_WaitGenerator,
27+
)
2428

2529

2630
def on_predicate(
2731
wait_gen: _WaitGenerator,
2832
predicate: _Predicate[Any] = operator.not_,
2933
*,
30-
max_tries: Optional[_MaybeCallable[int]] = None,
31-
max_time: Optional[_MaybeCallable[float]] = None,
32-
jitter: Union[_Jitterer, None] = full_jitter,
33-
on_success: Union[_Handler, Iterable[_Handler], None] = None,
34-
on_backoff: Union[_Handler, Iterable[_Handler], None] = None,
35-
on_giveup: Union[_Handler, Iterable[_Handler], None] = None,
34+
max_tries: _MaybeCallable[int] | None = None,
35+
max_time: _MaybeCallable[float] | None = None,
36+
jitter: _Jitterer | None = full_jitter,
37+
on_success: _Handler | Iterable[_Handler] | None = None,
38+
on_backoff: _Handler | Iterable[_Handler] | None = None,
39+
on_giveup: _Handler | Iterable[_Handler] | None = None,
3640
logger: _MaybeLogger = "backoff",
3741
backoff_log_level: int = logging.INFO,
3842
giveup_log_level: int = logging.ERROR,
@@ -124,15 +128,15 @@ def decorate(target):
124128

125129
def on_exception(
126130
wait_gen: _WaitGenerator,
127-
exception: _MaybeSequence[Type[Exception]],
131+
exception: _MaybeSequence[type[Exception]],
128132
*,
129-
max_tries: Optional[_MaybeCallable[int]] = None,
130-
max_time: Optional[_MaybeCallable[float]] = None,
131-
jitter: Union[_Jitterer, None] = full_jitter,
133+
max_tries: _MaybeCallable[int] | None = None,
134+
max_time: _MaybeCallable[float] | None = None,
135+
jitter: _Jitterer | None = full_jitter,
132136
giveup: _Predicate[Exception] = lambda e: False,
133-
on_success: Union[_Handler, Iterable[_Handler], None] = None,
134-
on_backoff: Union[_Handler, Iterable[_Handler], None] = None,
135-
on_giveup: Union[_Handler, Iterable[_Handler], None] = None,
137+
on_success: _Handler | Iterable[_Handler] | None = None,
138+
on_backoff: _Handler | Iterable[_Handler] | None = None,
139+
on_giveup: _Handler | Iterable[_Handler] | None = None,
136140
raise_on_giveup: bool = True,
137141
logger: _MaybeLogger = "backoff",
138142
backoff_log_level: int = logging.INFO,

backoff/_typing.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1+
from __future__ import annotations
2+
13
import logging
2-
from types import FunctionType
34
from typing import (
5+
TYPE_CHECKING,
46
Any,
57
Callable,
68
Coroutine,
7-
Dict,
89
Generator,
910
Sequence,
10-
Tuple,
1111
TypedDict,
1212
TypeVar,
1313
Union,
1414
)
1515

16+
if TYPE_CHECKING:
17+
from types import FunctionType
18+
1619

1720
class _Details(TypedDict):
1821
target: FunctionType
19-
args: Tuple[Any, ...]
20-
kwargs: Dict[str, Any]
22+
args: tuple[Any, ...]
23+
kwargs: dict[str, Any]
2124
tries: int
2225
elapsed: float
2326

backoff/_wait_gen.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
from __future__ import annotations
2+
13
import itertools
24
import math
3-
from typing import Any, Callable, Generator, Iterable, Optional, Union
5+
from typing import Any, Callable, Generator, Iterable
46

57

68
def expo(
79
base: float = 2,
810
factor: float = 1,
9-
max_value: Optional[float] = None,
11+
max_value: float | None = None,
1012
) -> Generator[float, Any, None]:
1113
"""Generator for exponential decay.
1214
@@ -32,7 +34,7 @@ def expo(
3234
def decay(
3335
initial_value: float = 1,
3436
decay_factor: float = 1,
35-
min_value: Optional[float] = None,
37+
min_value: float | None = None,
3638
) -> Generator[float, Any, None]:
3739
"""Generator for exponential decay[1]:
3840
@@ -57,7 +59,7 @@ def decay(
5759
yield min_value
5860

5961

60-
def fibo(max_value: Optional[int] = None) -> Generator[int, None, None]:
62+
def fibo(max_value: int | None = None) -> Generator[int, None, None]:
6163
"""Generator for fibonaccial decay.
6264
6365
Args:
@@ -79,7 +81,7 @@ def fibo(max_value: Optional[int] = None) -> Generator[int, None, None]:
7981

8082

8183
def constant(
82-
interval: Union[int, Iterable[float]] = 1,
84+
interval: int | Iterable[float] = 1,
8385
) -> Generator[float, None, None]:
8486
"""Generator for constant intervals.
8587

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ extend-select = [
194194
"B", # flake8-bugbear
195195
"C4", # flake8-comprehensions
196196
"DTZ", # flake8-datetimez
197+
"FA", # flake8-future-annotations
197198
"ISC", # flake8-implicit-str-concat
198199
"ICN", # flake8-import-conventions
199200
"LOG", # flake8-logging

0 commit comments

Comments
 (0)