Skip to content

Commit ace90a5

Browse files
committed
finally done with type hinting issues between python versions?
1 parent ef34212 commit ace90a5

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

python_utils/containers.py

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

25-
OnDuplicate: types.Literal['raise', 'ignore']
26-
2725

2826
class CastedDictBase(types.Dict[KT, VT], abc.ABC):
2927
_key_cast: KT_cast
@@ -211,7 +209,11 @@ class UniqueList(types.List[VT]):
211209

212210
_set: set[VT]
213211

214-
def __init__(self, *args: VT, on_duplicate: OnDuplicate = 'ignore'):
212+
def __init__(
213+
self,
214+
*args: VT,
215+
on_duplicate: types.Literal['raise', 'ignore'] = 'ignore'
216+
):
215217
self.on_duplicate = on_duplicate
216218
self._set = set()
217219
super().__init__()

python_utils/types.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import datetime
22
import decimal
3+
import sys
34
from typing import * # type: ignore # pragma: no cover
45

56
# import * does not import Pattern
67
from typing import Pattern
78

8-
try:
9-
from typing import Literal, SupportsIndex # type: ignore
10-
except ImportError:
9+
if sys.version_info >= (3, 8): # pragma: no cover
10+
from typing import Literal, SupportsIndex
11+
else: # pragma: no cover
1112
from typing_extensions import Literal, SupportsIndex
1213

1314
# Quickhand for optional because it gets so much use. If only Python had
@@ -38,9 +39,9 @@
3839
None,
3940
]
4041

41-
assert Pattern # type: ignore
42-
assert Literal
43-
assert SupportsIndex
42+
assert Pattern is not None # type: ignore
43+
assert Literal is not None
44+
assert SupportsIndex is not None
4445

4546
__all__ = [
4647
'OptionalScope',

setup.py

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

17-
install_requires = []
18-
1917
if __name__ == '__main__':
2018
setuptools.setup(
2119
python_requires='>3.6.0',

0 commit comments

Comments
 (0)