-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowProtocolType.py
More file actions
50 lines (33 loc) · 849 Bytes
/
ShowProtocolType.py
File metadata and controls
50 lines (33 loc) · 849 Bytes
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
import typing as t
T = t.TypeVar('T')
G = t.TypeVar('G')
class ICopy(t.Protocol[T]):
def copy(self) -> 't.Protocol[T]':
return self
class MyAPI:
@t.overload
def apply(self, arg1: ICopy[T], arg2: ICopy[G]):
...
@t.overload
def apply(self, arg1: int, arg2: int):
...
def apply(self, *args, **kwargs):
# implementation
pass
s = MyAPI()
s.apply(1.0) # get warning
s.apply([]) # get warning
s.apply(1, 2)
s.apply({}, {})
s.apply([], {})
def make_const_named_token_type(name, bases, ns: dict):
ns['token'] = '{}{}'.format(name, len(name))
return type(name, bases, ns)
class TokenA(metaclass=make_const_named_token_type):
token: str
pass
class TokenBB(metaclass=make_const_named_token_type):
token: str
pass
print(TokenA.token)
print(TokenBB.token)