Skip to content

Commit

Permalink
Merge branch 'release/3.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Feb 9, 2023
2 parents 07a7bee + e204544 commit bfe4693
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion python_utils/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
)
__url__: str = 'https://github.com/WoLpH/python-utils'
# Omit type info due to automatic versioning script
__version__ = '3.5.1'
__version__ = '3.5.2'
4 changes: 4 additions & 0 deletions python_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
types,
)
from .aio import acount
from .containers import CastedDict, LazyCastedDict, UniqueList
from .converters import remap, scale_1024, to_float, to_int, to_str, to_unicode
from .decorators import listify, set_attributes
from .exceptions import raise_exception, reraise
Expand Down Expand Up @@ -70,4 +71,7 @@
'raise_exception',
'Logged',
'LoggerBase',
'CastedDict',
'LazyCastedDict',
'UniqueList',
]
18 changes: 12 additions & 6 deletions python_utils/containers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import abc
import typing
from typing import Any, Generator
Expand All @@ -9,11 +7,17 @@
if typing.TYPE_CHECKING:
import _typeshed # noqa: F401

#: A type alias for a type that can be used as a key in a dictionary.
KT = types.TypeVar('KT')
#: A type alias for a type that can be used as a value in a dictionary.
VT = types.TypeVar('VT')
#: A type alias for a dictionary with keys of type KT and values of type VT.
DT = types.Dict[KT, VT]
#: A type alias for the casted type of a dictionary key.
KT_cast = types.Optional[types.Callable[[Any], KT]]
#: A type alias for the casted type of a dictionary value.
VT_cast = types.Optional[types.Callable[[Any], VT]]
#: A type alias for the hashable values of the `UniqueList`
HT = types.TypeVar('HT', bound=types.Hashable)

# Using types.Union instead of | since Python 3.7 doesn't fully support it
Expand Down Expand Up @@ -61,7 +65,7 @@ class CastedDict(CastedDictBase[KT, VT]):
Note that you can specify the types for mypy and type hinting with:
CastedDict[int, int](int, int)
>>> d = CastedDict(int, int)
>>> d: CastedDict[int, int] = CastedDict(int, int)
>>> d[1] = 2
>>> d['3'] = '4'
>>> d.update({'5': '6'})
Expand Down Expand Up @@ -105,7 +109,7 @@ class LazyCastedDict(CastedDictBase[KT, VT]):
Note that you can specify the types for mypy and type hinting with:
LazyCastedDict[int, int](int, int)
>>> d = LazyCastedDict(int, int)
>>> d: LazyCastedDict[int, int] = LazyCastedDict(int, int)
>>> d[1] = 2
>>> d['3'] = '4'
>>> d.update({'5': '6'})
Expand Down Expand Up @@ -159,7 +163,9 @@ def __getitem__(self, key: Any) -> VT:

return value

def items(self) -> Generator[tuple[KT, VT], None, None]: # type: ignore
def items( # type: ignore
self,
) -> Generator[types.Tuple[KT, VT], None, None]:
if self._value_cast is None:
yield from super().items()
else:
Expand Down Expand Up @@ -208,7 +214,7 @@ class UniqueList(types.List[HT]):
ValueError: Duplicate value: 4
'''

_set: set[HT]
_set: types.Set[HT]

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ commands =
mkdir -p docs/_static
sphinx-apidoc -o docs/ python_utils
rm -f docs/modules.rst
sphinx-build -n -W -b html -d docs/_build/doctrees docs docs/_build/html {posargs}
sphinx-build -W -b html -d docs/_build/doctrees docs docs/_build/html {posargs}

0 comments on commit bfe4693

Please sign in to comment.