Skip to content

Commit 8d9cb08

Browse files
committed
fixing code style
1 parent f47abbe commit 8d9cb08

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

ellar_throttler/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def setup(
3838
use_value=ThrottlerModuleOptions(
3939
limit=limit,
4040
ttl=ttl,
41-
skip_if=skip_if, # type:ignore[arg-type]
41+
skip_if=skip_if,
4242
),
4343
),
4444
],

ellar_throttler/throttler_guard.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ async def can_activate(self, context: IExecutionContext) -> bool:
3434
# Return early if the current route should be skipped.
3535
# or self.options.skipIf?.(context)
3636

37-
if (
38-
self.reflector.get_all_and_override(THROTTLER_SKIP, handler, class_ref)
39-
or self.options.skip_if
40-
and self.options.skip_if(context)
37+
if self.reflector.get_all_and_override(THROTTLER_SKIP, handler, class_ref) or (
38+
self.options.skip_if and self.options.skip_if(context)
4139
):
4240
return True
4341

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import dataclasses
21
import typing as t
32

43
from ellar.core import IExecutionContext
4+
from ellar.serializer import Serializer
55

66

7-
@dataclasses.dataclass
8-
class ThrottlerModuleOptions:
7+
class ThrottlerModuleOptions(Serializer):
98
# The amount of requests that are allowed within the ttl's time window.
109
limit: int
1110

@@ -14,4 +13,4 @@ class ThrottlerModuleOptions:
1413

1514
# A factory method to determine if throttling should be skipped.
1615
# This can be based on the incoming context.
17-
skip_if: t.Callable[[IExecutionContext], bool] = None # type:ignore[assignment]
16+
skip_if: t.Optional[t.Callable[[IExecutionContext], bool]] = None
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import dataclasses
1+
from ellar.serializer import Serializer
22

33

4-
@dataclasses.dataclass
5-
class ThrottlerStorageOption:
4+
class ThrottlerStorageOption(Serializer):
65
total_hits: int
76
expires_at: float

ellar_throttler/throttler_storage_record.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import dataclasses
1+
from ellar.serializer import Serializer
22

33

4-
@dataclasses.dataclass
5-
class ThrottlerStorageRecord:
4+
class ThrottlerStorageRecord(Serializer):
65
# Amount of requests done by a specific user (partially based on IP).
76
total_hits: int
87
# Amount of seconds when the `total_hits` should expire.

0 commit comments

Comments
 (0)