Skip to content

Commit

Permalink
Set requires-python>=3.9 now that 3.8 is end-of-life
Browse files Browse the repository at this point in the history
...and use more concise type[]/tuple[]/list[] etc. type hint syntax in
places where it could not be used before due to supporting Python 3.8.
  • Loading branch information
jab committed Oct 4, 2024
1 parent c140c87 commit f73239e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ repos:
rev: v0.6.8
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --unsafe-fixes]
- id: ruff-format

- repo: https://github.com/shellcheck-py/shellcheck-py
Expand Down
6 changes: 3 additions & 3 deletions bidict/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
from ._typing import MapOrItems


OldKV = t.Tuple[OKT[KT], OVT[VT]]
OldKV = tuple[OKT[KT], OVT[VT]]
DedupResult = t.Optional[OldKV[KT, VT]]
Unwrites = t.List[t.Tuple[t.Any, ...]]
Unwrites = list[tuple[t.Any, ...]]
BT = t.TypeVar('BT', bound='BidictBase[t.Any, t.Any]')


Expand Down Expand Up @@ -139,7 +139,7 @@ def _make_inv_cls(cls: type[BT]) -> type[BT]:
diff['_inv_cls'] = cls
inv_cls = type(f'{cls.__name__}Inv', (cls, GeneratedBidictInverse), diff)
inv_cls.__module__ = cls.__module__
return t.cast(t.Type[BT], inv_cls)
return t.cast(type[BT], inv_cls)

@classmethod
def _inv_cls_dict_diff(cls) -> dict[str, t.Any]:
Expand Down
2 changes: 1 addition & 1 deletion bidict/_orderedbidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __reversed__(self) -> t.Iterator[tuple[KT, VT]]:
# For better performance, make _OrderedBidictKeysView and _OrderedBidictItemsView delegate
# to backing dicts for the methods they inherit from collections.abc.Set. (Cannot delegate
# for __iter__ and __reversed__ since they are order-sensitive.) See also: https://bugs.python.org/issue46713
_OView = t.Union[t.Type[_OrderedBidictKeysView[KT]], t.Type[_OrderedBidictItemsView[KT, t.Any]]]
_OView = t.Union[type[_OrderedBidictKeysView[KT]], type[_OrderedBidictItemsView[KT, t.Any]]]
_setmethodnames: t.Iterable[str] = (
'__lt__ __le__ __gt__ __ge__ __eq__ __ne__ __sub__ __rsub__ '
'__or__ __ror__ __xor__ __rxor__ __and__ __rand__ isdisjoint'
Expand Down
4 changes: 2 additions & 2 deletions bidict/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
VT_co = t.TypeVar('VT_co', covariant=True)


Items = t.Iterable[t.Tuple[KT, VT]]
Items = t.Iterable[tuple[KT, VT]]


@t.runtime_checkable
Expand All @@ -30,7 +30,7 @@ def __getitem__(self, __key: KT) -> VT_co: ...


MapOrItems = t.Union[Maplike[KT, VT], Items[KT, VT]]
ItemsIter = t.Iterator[t.Tuple[KT, VT]]
ItemsIter = t.Iterator[tuple[KT, VT]]


class MissingT(Enum):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "The bidirectional mapping library for Python."
authors = [{ name = "Joshua Bronson", email = "[email protected]" }]
license = { text = "MPL 2.0" }
dependencies = []
requires-python = ">=3.8"
requires-python = ">=3.9"
readme = "README.rst"
keywords = [
"bidict",
Expand Down
6 changes: 3 additions & 3 deletions tests/bidict_test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __getitem__(self, key: KT) -> VT:


BB = BidictBase[KT, VT]
BT = t.Type[BB[KT, VT]]
BT = type[BB[KT, VT]]
user_bidict_types: list[BT[t.Any, t.Any]] = []


Expand Down Expand Up @@ -78,13 +78,13 @@ class UserBiNotOwnInv(bidict[KT, VT]):
UserBiNotOwnInvInv = UserBiNotOwnInv._inv_cls
assert UserBiNotOwnInvInv is not UserBiNotOwnInv

BTs = t.Tuple[BT[t.Any, t.Any], ...]
BTs = tuple[BT[t.Any, t.Any], ...]
builtin_bidict_types: BTs = (bidict, frozenbidict, OrderedBidict)
bidict_types: BTs = (*builtin_bidict_types, *user_bidict_types)
update_arg_types = (*bidict_types, list, dict, iter, SupportsKeysAndGetItem)
mutable_bidict_types: BTs = tuple(t for t in bidict_types if issubclass(t, MutableBidirectionalMapping))
assert frozenbidict not in mutable_bidict_types
MBT = t.Union[t.Type[bidict[KT, VT]], t.Type[OrderedBidict[KT, VT]]]
MBT = t.Union[type[bidict[KT, VT]], type[OrderedBidict[KT, VT]]]


def should_be_reversible(bi_t: BT[KT, VT]) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
from bidict._typing import MapOrItems


Items = t.Sequence[t.Tuple[int, int]]
Items121 = t.Dict[t.Any, t.Any]
Items = t.Sequence[tuple[int, int]]
Items121 = dict[t.Any, t.Any]

ks = tuple(range(1, 5))
vs = tuple(range(-1, -5, -1))
Expand Down

0 comments on commit f73239e

Please sign in to comment.