Skip to content

Commit 60d6d16

Browse files
committed
python 3.7 type compatibility
1 parent 3c722f3 commit 60d6d16

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

python_utils/containers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'_typeshed.SupportsKeysAndGetItem[KT, VT]',
2323
]
2424

25-
OnDuplicate = types.Literal['raise', 'ignore']
25+
OnDuplicate: types.Literal['raise', 'ignore']
2626

2727

2828
class CastedDictBase(types.Dict[KT, VT], abc.ABC):
@@ -208,6 +208,7 @@ class UniqueList(types.List[VT]):
208208
...
209209
ValueError: Duplicate value: 4
210210
'''
211+
211212
_set: set[VT]
212213

213214
def __init__(self, *args: VT, on_duplicate: OnDuplicate = 'ignore'):
@@ -275,9 +276,8 @@ def __setitem__(self, indices, values) -> None:
275276
super().__setitem__(indices, values)
276277

277278
def __delitem__(
278-
self,
279-
index: types.Union[types.SupportsIndex, slice]
280-
) -> None:
279+
self, index: types.Union[types.SupportsIndex, slice]
280+
) -> None:
281281
if isinstance(index, slice):
282282
for value in self[index]:
283283
self._set.remove(value)

python_utils/types.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# import * does not import Pattern
66
from typing import Pattern
77

8+
try:
9+
from typing import Literal, SupportsIndex # type: ignore
10+
except ImportError:
11+
from typing_extensions import Literal, SupportsIndex
12+
813
# Quickhand for optional because it gets so much use. If only Python had
914
# support for an optional type shorthand such as `SomeType?` instead of
1015
# `Optional[SomeType]`.
@@ -33,7 +38,9 @@
3338
None,
3439
]
3540

36-
assert Pattern
41+
assert Pattern # type: ignore
42+
assert Literal
43+
assert SupportsIndex
3744

3845
__all__ = [
3946
'OptionalScope',
@@ -52,6 +59,7 @@
5259
'ForwardRef',
5360
'Generic',
5461
'Literal',
62+
'SupportsIndex',
5563
'Optional',
5664
'ParamSpec',
5765
'Protocol',

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
else:
1515
long_description = 'See http://pypi.python.org/pypi/python-utils/'
1616

17+
install_requires = []
18+
1719
if __name__ == '__main__':
1820
setuptools.setup(
1921
python_requires='>3.6.0',
@@ -29,6 +31,7 @@
2931
),
3032
package_data={'python_utils': ['py.typed']},
3133
long_description=long_description,
34+
install_requires=['typing_extensions;python_version<"3.8"'],
3235
tests_require=['pytest'],
3336
extras_require={
3437
'loguru': [

0 commit comments

Comments
 (0)