Skip to content

Commit e43a512

Browse files
committed
Fixed tests and more Python version compatibility
1 parent c7a3c46 commit e43a512

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

_python_utils_tests/test_aio.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from datetime import datetime
22
import pytest
33
import asyncio
4+
5+
from python_utils import types
46
from python_utils.aio import acount
57

68

79
@pytest.mark.asyncio
810
async def test_acount(monkeypatch: pytest.MonkeyPatch):
9-
sleeps: list[float] = []
11+
sleeps: types.List[float] = []
1012

1113
async def mock_sleep(delay: float):
1214
sleeps.append(delay)

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ addopts =
77
--doctest-modules
88
--cov python_utils
99
--cov-report term-missing
10-
--mypy
10+
; --mypy
1111

1212
doctest_optionflags =
1313
ALLOW_UNICODE

python_utils/containers.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# pyright: reportIncompatibleMethodOverride=false
22
import abc
33
import typing
4-
from typing import Any, Generator
54

65
from . import types
76

@@ -15,18 +14,17 @@
1514
#: A type alias for a dictionary with keys of type KT and values of type VT.
1615
DT = types.Dict[KT, VT]
1716
#: A type alias for the casted type of a dictionary key.
18-
KT_cast = types.Optional[types.Callable[[Any], KT]]
17+
KT_cast = types.Optional[types.Callable[..., KT]]
1918
#: A type alias for the casted type of a dictionary value.
20-
VT_cast = types.Optional[types.Callable[[Any], VT]]
19+
VT_cast = types.Optional[types.Callable[..., VT]]
2120
#: A type alias for the hashable values of the `UniqueList`
2221
HT = types.TypeVar('HT', bound=types.Hashable)
2322

2423
# Using types.Union instead of | since Python 3.7 doesn't fully support it
2524
DictUpdateArgs = types.Union[
26-
types.Mapping[types.Any, types.Any],
27-
types.Iterable[
28-
types.Union[types.Tuple[Any, Any], types.Mapping[types.Any, types.Any]]
29-
],
25+
types.Mapping[KT, VT],
26+
types.Iterable[types.Tuple[KT, VT]],
27+
types.Iterable[types.Mapping[KT, VT]],
3028
'_typeshed.SupportsKeysAndGetItem[KT, VT]',
3129
]
3230

@@ -56,7 +54,7 @@ def update(
5654
for key, value in kwargs.items():
5755
self[key] = value
5856

59-
def __setitem__(self, key: Any, value: Any) -> None:
57+
def __setitem__(self, key: types.Any, value: types.Any) -> None:
6058
if self._key_cast is not None:
6159
key = self._key_cast(key)
6260

@@ -168,14 +166,16 @@ def __getitem__(self, key: types.Any) -> VT:
168166

169167
return value
170168

171-
def items(self) -> Generator[tuple[KT, VT], None, None]: # type: ignore
169+
def items( # type: ignore
170+
self,
171+
) -> types.Generator[types.Tuple[KT, VT], None, None]:
172172
if self._value_cast is None:
173173
yield from super().items()
174174
else:
175175
for key, value in super().items():
176176
yield key, self._value_cast(value)
177177

178-
def values(self) -> Generator[VT, None, None]: # type: ignore
178+
def values(self) -> types.Generator[VT, None, None]: # type: ignore
179179
if self._value_cast is None:
180180
yield from super().values()
181181
else:

0 commit comments

Comments
 (0)