Skip to content

Commit

Permalink
Merge branch 'release/3.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Feb 8, 2023
2 parents 5ed3147 + 544d13e commit 07a7bee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 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.0'
__version__ = '3.5.1'
15 changes: 8 additions & 7 deletions python_utils/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DT = types.Dict[KT, VT]
KT_cast = types.Optional[types.Callable[[Any], KT]]
VT_cast = types.Optional[types.Callable[[Any], VT]]
HT = types.TypeVar('HT', bound=types.Hashable)

# Using types.Union instead of | since Python 3.7 doesn't fully support it
DictUpdateArgs = types.Union[
Expand Down Expand Up @@ -173,7 +174,7 @@ def values(self) -> Generator[VT, None, None]: # type: ignore
yield self._value_cast(value)


class UniqueList(types.List[VT]):
class UniqueList(types.List[HT]):
'''
A list that only allows unique values. Duplicate values are ignored by
default, but can be configured to raise an exception instead.
Expand Down Expand Up @@ -207,11 +208,11 @@ class UniqueList(types.List[VT]):
ValueError: Duplicate value: 4
'''

_set: set[VT]
_set: set[HT]

def __init__(
self,
*args: VT,
*args: HT,
on_duplicate: types.Literal['raise', 'ignore'] = 'ignore',
):
self.on_duplicate = on_duplicate
Expand All @@ -220,7 +221,7 @@ def __init__(
for arg in args:
self.append(arg)

def insert(self, index: types.SupportsIndex, value: VT) -> None:
def insert(self, index: types.SupportsIndex, value: HT) -> None:
if value in self._set:
if self.on_duplicate == 'raise':
raise ValueError('Duplicate value: %s' % value)
Expand All @@ -230,7 +231,7 @@ def insert(self, index: types.SupportsIndex, value: VT) -> None:
self._set.add(value)
super().insert(index, value)

def append(self, value: VT) -> None:
def append(self, value: HT) -> None:
if value in self._set:
if self.on_duplicate == 'raise':
raise ValueError('Duplicate value: %s' % value)
Expand All @@ -244,11 +245,11 @@ def __contains__(self, item):
return item in self._set

@types.overload
def __setitem__(self, indices: types.SupportsIndex, values: VT) -> None:
def __setitem__(self, indices: types.SupportsIndex, values: HT) -> None:
...

@types.overload
def __setitem__(self, indices: slice, values: types.Iterable[VT]) -> None:
def __setitem__(self, indices: slice, values: types.Iterable[HT]) -> None:
...

def __setitem__(self, indices, values) -> None:
Expand Down
6 changes: 5 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ deps = -r{toxinidir}/_python_utils_tests/requirements.txt
commands = mypy {posargs}

[testenv:docs]
changedir =
basepython = python3
deps = -r{toxinidir}/docs/requirements.txt
allowlist_externals =
rm
mkdir
whitelist_externals =
rm
cd
Expand All @@ -56,5 +61,4 @@ commands =
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}
deps = -r{toxinidir}/docs/requirements.txt

0 comments on commit 07a7bee

Please sign in to comment.