Skip to content

Commit 8d4f656

Browse files
committed
fix iterator and generatortype hints
(cherry picked from commit 71ffd57)
1 parent c8a6c01 commit 8d4f656

File tree

14 files changed

+29
-25
lines changed

14 files changed

+29
-25
lines changed

django_valkey/base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import builtins
2-
from asyncio import iscoroutinefunction
32
import contextlib
43
import functools
54
import logging
5+
from asyncio import iscoroutinefunction
6+
from collections.abc import AsyncGenerator, Callable, Iterator
67
from typing import (
78
Any,
89
TypeVar,
910
Generic,
10-
Iterator,
11-
AsyncGenerator,
12-
Callable,
1311
TYPE_CHECKING,
1412
)
1513

@@ -445,7 +443,7 @@ async def ttl(self, *args, **kwargs) -> int:
445443
async def pttl(self, *args, **kwargs) -> int:
446444
return await self.client.pttl(*args, **kwargs)
447445

448-
async def iter_keys(self, *args, **kwargs) -> AsyncGenerator[Any]:
446+
async def iter_keys(self, *args, **kwargs) -> AsyncGenerator[Any, None]:
449447
async with contextlib.aclosing(self.client.iter_keys(*args, **kwargs)) as it:
450448
async for key in it:
451449
yield key
@@ -495,7 +493,7 @@ async def srem(self, *args, **kwargs) -> int:
495493
async def sscan(self, *args, **kwargs) -> builtins.set[Any]:
496494
return await self.client.sscan(*args, **kwargs)
497495

498-
async def sscan_iter(self, *args, **kwargs) -> AsyncGenerator[Any]:
496+
async def sscan_iter(self, *args, **kwargs) -> AsyncGenerator[Any, None]:
499497
async with contextlib.aclosing(self.client.sscan_iter(*args, **kwargs)) as it:
500498
async for key in it:
501499
yield key

django_valkey/base_client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
import re
44
import socket
55
import time
6+
from collections.abc import AsyncGenerator, Iterable, Iterator
67
from contextlib import suppress
78
from typing import (
89
Any,
910
Dict,
10-
Iterable,
11-
Iterator,
1211
List,
1312
Set,
1413
Tuple,
1514
cast,
1615
TYPE_CHECKING,
1716
Generic,
1817
TypeVar,
19-
AsyncGenerator,
2018
)
2119

2220
from django.conf import settings
@@ -879,7 +877,7 @@ def iter_keys(
879877
) -> Iterator[str]:
880878
"""
881879
Same as keys, but uses cursors
882-
for make memory efficient keys iteration.
880+
to make memory efficient keys iteration.
883881
"""
884882

885883
client = self._get_client(write=False, client=client)
@@ -1841,10 +1839,10 @@ async def iter_keys(
18411839
itersize: int | None = None,
18421840
client: Backend | Any | None = None,
18431841
version: int | None = None,
1844-
) -> AsyncGenerator:
1842+
) -> AsyncGenerator[str, None]:
18451843
"""
18461844
Same as keys, but uses cursors
1847-
for make memory efficient keys iteration.
1845+
to make memory efficient keys iteration.
18481846
"""
18491847
client = await self._get_client(write=False, client=client)
18501848
pattern = self.make_pattern(search, version=version)

django_valkey/client/herd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import socket
2-
from typing import Any, Iterable
2+
from collections.abc import Iterable
3+
from typing import Any
34

45
from valkey import Valkey
56
from valkey.exceptions import ConnectionError, ResponseError, TimeoutError

django_valkey/hash_ring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import bisect
22
import hashlib
3-
from typing import Dict, Iterable, Iterator, List, Tuple
3+
from collections.abc import Iterable, Iterator
4+
from typing import Dict, List, Tuple
45

56

67
class HashRing:

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterable
1+
from collections.abc import Iterable
22

33
import pytest
44
import pytest_asyncio

tests/test_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import datetime
22
import threading
33
import time
4+
from collections.abc import Iterable
45
from datetime import timedelta
5-
from typing import Iterable, List, cast
6+
from typing import List, cast
67
from unittest.mock import patch
78

89
import pytest

tests/test_cache_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
2-
from typing import Iterable, cast
2+
from collections.abc import Iterable
3+
from typing import cast
34

45
import pytest
56
from django.core.cache import caches

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterable
1+
from collections.abc import Iterable
22
from unittest.mock import Mock, call, patch
33

44
import pytest

tests/tests_async/test_backend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import asyncio
22
import contextlib
33
import datetime
4-
from datetime import timedelta
54
import threading
6-
from typing import Iterable, List, cast
5+
from collections.abc import Iterable
6+
from datetime import timedelta
7+
from typing import List, cast
78
from unittest.mock import patch, AsyncMock
89

910
import pytest

tests/tests_async/test_cache_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import copy
3-
from typing import Iterable, cast
3+
from collections.abc import Iterable
4+
from typing import cast
45

56
import pytest
67
from pytest import LogCaptureFixture

0 commit comments

Comments
 (0)