-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathtyping.py
152 lines (112 loc) · 3.32 KB
/
typing.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import sys
if sys.version_info >= (3, 11, 0):
from enum import Enum, IntEnum, IntFlag, StrEnum
from typing import Any
from typing import Callable
from typing import cast
from typing import Deque
from typing import Dict
from typing import final
from typing import Generator
from typing import Generic
from typing import IO
from typing import Iterable
from typing import Iterator
from typing import List
from typing import Literal
from typing import Mapping
from typing import NotRequired
from typing import Optional
from typing import ParamSpec
from typing import Protocol
from typing import Required
from typing import Sequence
from typing import Set
from typing import Tuple
from typing import Type
from typing import TYPE_CHECKING
from typing import TypedDict
from typing import TypeGuard
from typing import TypeVar
from typing import Union
else:
TYPE_CHECKING = False
def cast(typ, val): # type: ignore
return val
def final(func): # type: ignore
return func
def _make_type(name: str) -> '_TypeMeta':
return _TypeMeta(name, (Type,), {}) # type: ignore
class _TypeMeta(type):
def __getitem__(self, args: 'Any') -> 'Any':
if not isinstance(args, tuple):
args = (args,)
name = '{}[{}]'.format(
str(self),
', '.join(map(str, args))
)
return _make_type(name)
def __str__(self) -> str:
return self.__name__
class Type(metaclass=_TypeMeta): # type: ignore
pass
class TypedDict(Type, dict): # type: ignore
def __init__(*args, **kwargs) -> None: # type: ignore
pass
class TypeGuard(Type): # type: ignore
pass
class Enum(Type): # type: ignore
pass
class IntEnum(Type): # type: ignore
pass
class IntFlag(Type): # type: ignore
pass
class StrEnum(Type): # type: ignore
pass
class Any(Type): # type: ignore
pass
class Callable(Type): # type: ignore
pass
class Deque(Type): # type: ignore
pass
class Dict(Type): # type: ignore
pass
class Generic(Type): # type: ignore
pass
class Generator(Type): # type: ignore
pass
class IO(Type): # type: ignore
pass
class Iterable(Type): # type: ignore
pass
class Iterator(Type): # type: ignore
pass
class List(Type): # type: ignore
pass
class Literal(Type): # type: ignore
pass
class Mapping(Type): # type: ignore
pass
class Optional(Type): # type: ignore
pass
class Set(Type): # type: ignore
pass
class Tuple(Type): # type: ignore
pass
class Union(Type): # type: ignore
pass
class Protocol(Type): # type: ignore
pass
class Sequence(Type): # type: ignore
pass
class Required(Type): # type: ignore
pass
class NotRequired(Type): # type: ignore
pass
def TypeVar(*args, **kwargs) -> Any: # type: ignore
return object
class ParamSpec(Type): # type: ignore
args = ...
kwargs = ...
def __init__(*args, **kwargs) -> None: # type: ignore
pass