Skip to content

Commit

Permalink
fixed some type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
amirreza8002 committed Jan 12, 2025
1 parent c4abd65 commit a967d64
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 47 deletions.
8 changes: 4 additions & 4 deletions django_valkey/async_cache/client/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def aadd(
self,
key,
value,
timeout: float | int | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: AValkey | Any | None = None,
) -> bool:
Expand Down Expand Up @@ -230,7 +230,7 @@ async def aget_lock(
self,
key,
version: int | None = None,
timeout: float | int | None = None,
timeout: float | None = None,
sleep: float = 0.1,
blocking: bool = True,
blocking_timeout: float | None = None,
Expand Down Expand Up @@ -407,7 +407,7 @@ async def aget_many(
async def aset_many(
self,
data: dict,
timeout: float | int | None = None,
timeout: int | None = None,
version: int | None = None,
client: AValkey | Any | None = None,
) -> None:
Expand Down Expand Up @@ -975,7 +975,7 @@ async def _aclose(self) -> None:
async def atouch(
self,
key,
timeout: float | int | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: AValkey | Any | None = None,
) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions django_valkey/client/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def set(
self,
key: KeyT,
value: EncodableT,
timeout: int | float | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: Valkey | Any | None = None,
nx: bool = False,
Expand Down Expand Up @@ -130,7 +130,7 @@ def add(
self,
key: KeyT,
value: EncodableT,
timeout: float | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: Valkey | Any | None = None,
) -> bool:
Expand Down Expand Up @@ -421,7 +421,7 @@ def get_many(
def set_many(
self,
data: dict[KeyT, EncodableT],
timeout: float | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: Valkey | Any | None = None,
) -> None:
Expand Down Expand Up @@ -948,7 +948,7 @@ def _close(self) -> None:
def touch(
self,
key: KeyT,
timeout: float | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: Valkey | Any | None = None,
) -> bool:
Expand Down
76 changes: 37 additions & 39 deletions django_valkey/client/sharded.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def add(
self,
key: KeyT,
value: EncodableT,
timeout: float | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> bool:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -69,7 +69,7 @@ def get(
key: KeyT,
default: Any | None = None,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> Any:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -81,7 +81,7 @@ def get_many(
self,
keys: KeyT,
version: int | None = None,
_client: Valkey | Any | None = None,
_client: Valkey | None = None,
) -> dict:
if not keys:
return {}
Expand All @@ -108,9 +108,9 @@ def set(
self,
key: KeyT,
value: EncodableT,
timeout: int | float | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
nx: bool = False,
xx: bool = False,
) -> bool:
Expand All @@ -134,9 +134,9 @@ def set(
def set_many(
self,
data: dict[KeyT, EncodableT],
timeout: float | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> None:
"""
Set a bunch of values in the cache at once from a dict of key/value
Expand All @@ -152,7 +152,7 @@ def mset(self, *args, **kwargs):
raise NotImplementedError

def has_key(
self, key: KeyT, version: int | None = None, client: Valkey | Any | None = None
self, key: KeyT, version: int | None = None, client: Valkey | None = None
) -> bool:
"""
Test if key exists.
Expand All @@ -173,7 +173,7 @@ def delete(
key: KeyT,
version: int | None = None,
prefix: str | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> int:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -182,7 +182,7 @@ def delete(
return super().delete(key=key, version=version, client=client)

def ttl(
self, key: KeyT, version: int | None = None, client: Valkey | Any | None = None
self, key: KeyT, version: int | None = None, client: Valkey | None = None
) -> int | None:
"""
Executes TTL valkey command and return the "time-to-live" of specified key.
Expand All @@ -196,7 +196,7 @@ def ttl(
return super().ttl(key=key, version=version, client=client)

def pttl(
self, key: KeyT, version: int | None = None, client: Valkey | Any | None = None
self, key: KeyT, version: int | None = None, client: Valkey | None = None
) -> int | None:
"""
Executes PTTL valkey command and return the "time-to-live" of specified key
Expand All @@ -210,7 +210,7 @@ def pttl(
return super().pttl(key=key, version=version, client=client)

def persist(
self, key: KeyT, version: int | None = None, client: Valkey | Any | None = None
self, key: KeyT, version: int | None = None, client: Valkey | None = None
) -> bool:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -223,7 +223,7 @@ def expire(
key: KeyT,
timeout: int | timedelta,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> bool:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -236,7 +236,7 @@ def pexpire(
key: KeyT,
timeout: int | timedelta,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> bool:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -249,7 +249,7 @@ def pexpire_at(
key: KeyT,
when: datetime | int,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> bool:
"""
Set an expiry flag on a ``key`` to ``when`` on a shard client.
Expand All @@ -267,7 +267,7 @@ def expire_at(
key: KeyT,
when: datetime | int,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> bool:
"""
Set an expiry flag on a ``key`` to ``when`` on a shard client.
Expand Down Expand Up @@ -310,9 +310,7 @@ def get_lock(
# TODO: delete in future.
lock = get_lock

def delete_many(
self, keys, version=None, _client: Valkey | Any | None = None
) -> int:
def delete_many(self, keys, version=None, _client: Valkey | None = None) -> int:
"""
Remove multiple keys at once.
"""
Expand All @@ -327,7 +325,7 @@ def incr_version(
key: KeyT,
delta: int = 1,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> int:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -345,7 +343,7 @@ def incr(
key: KeyT,
delta: int = 1,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
**kwargs,
) -> int:
if client is None:
Expand All @@ -359,7 +357,7 @@ def decr(
key: KeyT,
delta: int = 1,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> int:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -371,7 +369,7 @@ def iter_keys(
self,
search: str,
itersize: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
version: int | None = None,
):
"""Not Implemented"""
Expand All @@ -382,7 +380,7 @@ def keys(
self,
search: str,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> list[str]:
pattern = self.make_pattern(search, version=version)
keys = []
Expand All @@ -400,7 +398,7 @@ def delete_pattern(
self,
pattern: str,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
itersize: int | None = None,
prefix: str | None = None,
) -> int:
Expand Down Expand Up @@ -429,9 +427,9 @@ def _close(self) -> None:
def touch(
self,
key: KeyT,
timeout: float | None = DEFAULT_TIMEOUT,
timeout: int | None = DEFAULT_TIMEOUT,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> bool:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -448,7 +446,7 @@ def sadd(
key: KeyT,
*values: Any,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> int:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -459,7 +457,7 @@ def scard(
self,
key: KeyT,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> int:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -470,7 +468,7 @@ def smembers(
self,
key: KeyT,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
return_set: bool = True,
) -> builtins.set[Any] | list[Any]:
if client is None:
Expand All @@ -486,7 +484,7 @@ def smove(
destination: KeyT,
member: Any,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> bool:
if client is None:
source = self.make_key(source, version=version)
Expand All @@ -506,7 +504,7 @@ def srem(
key: KeyT,
*members,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> int:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -520,7 +518,7 @@ def sscan(
match: str | None = None,
count: int = 10,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
return_set: bool = True,
) -> tuple[int, builtins.set[Any]] | tuple[int, list[Any]]:
if client is None:
Expand All @@ -542,7 +540,7 @@ def sscan_iter(
match: str | None = None,
count: int = 10,
version: int | None = None,
client: Valkey | Any | Any | None = None,
client: Valkey | None = None,
) -> Iterator[Any]:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -556,7 +554,7 @@ def srandmember(
key: KeyT,
count: int | None = None,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
return_set: bool = True,
) -> builtins.set | list | Any:
if client is None:
Expand All @@ -571,7 +569,7 @@ def sismember(
key: KeyT,
member: Any,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> bool:
if client is None:
key = self.make_key(key, version=version)
Expand All @@ -583,7 +581,7 @@ def spop(
key: KeyT,
count: int | None = None,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
return_set: bool = True,
) -> builtins.set | list | Any:
if client is None:
Expand All @@ -598,7 +596,7 @@ def smismember(
key: KeyT,
*members,
version: int | None = None,
client: Valkey | Any | None = None,
client: Valkey | None = None,
) -> list[bool]:
if client is None:
key = self.make_key(key, version=version)
Expand Down

0 comments on commit a967d64

Please sign in to comment.