Skip to content

Commit

Permalink
Use strong reference to storage in strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaifee committed Apr 17, 2023
1 parent e434204 commit 8a3ec0f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions limits/aio/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Asynchronous rate limiting strategies
"""

import weakref
from abc import ABC, abstractmethod
from typing import cast

Expand All @@ -15,7 +14,7 @@
class RateLimiter(ABC):
def __init__(self, storage: StorageTypes):
assert isinstance(storage, Storage)
self.storage: Storage = weakref.proxy(storage)
self.storage: Storage = storage

@abstractmethod
async def hit(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion limits/storage/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from limits.typing import Dict, List, Optional, Tuple


class LockableEntry(threading._RLock):
class LockableEntry(threading._RLock): # type: ignore
def __init__(self, expiry: float) -> None:
self.atime = time.time()
self.expiry = self.atime + expiry
Expand Down
3 changes: 1 addition & 2 deletions limits/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Rate limiting strategies
"""

import weakref
from abc import ABCMeta, abstractmethod
from typing import Dict, Type, Union, cast

Expand All @@ -14,7 +13,7 @@
class RateLimiter(metaclass=ABCMeta):
def __init__(self, storage: StorageTypes):
assert isinstance(storage, Storage)
self.storage: Storage = weakref.proxy(storage)
self.storage: Storage = storage

@abstractmethod
def hit(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:
Expand Down

0 comments on commit 8a3ec0f

Please sign in to comment.