-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes_extensions.py
executable file
·47 lines (35 loc) · 1.25 KB
/
types_extensions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from version_checking import get_current_version, PythonVersion, _assert_py_version
_assert_py_version(PythonVersion(3, 6))
from decimal import Decimal
from typing import *
void = NULL = null = nil = type(None)
if get_current_version() >= PythonVersion(3, 9):
list_type = list
dict_type = dict
tuple_type = tuple
set_type = set
else:
list_type = List
dict_type = Dict
tuple_type = Tuple
set_type = Set
if get_current_version() >= PythonVersion(3, 10):
Number_t = int | float | complex | Decimal
string_like = str | bytes
primitives = int | float | void | string_like | bool
single_value_iterables = list_type | tuple_type | set_type | frozenset
else:
Number_t = Union[int, float, complex, Decimal]
string_like = Union[str, bytes]
primitives = Union[int, float, void, string_like, bool]
single_value_iterables = Union[list_type, tuple_type, set_type, frozenset]
Function = Method = Callable
HashMap = dict
def const(t_: type) -> type:
return Final[t_]
def safe_type(type_: type) -> Union:
return Union[type_, void]
def is_of_type(actual_t: Any, expected_t: type) -> bool:
if hasattr(expected_t, '__args__'):
return actual_t in expected_t.__args__
return actual_t == expected_t