-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.py
More file actions
32 lines (26 loc) · 759 Bytes
/
a.py
File metadata and controls
32 lines (26 loc) · 759 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
from typing import TypeVar, Callable, List, Dict, TYPE_CHECKING
from typing_extensions import Protocol
from typing import Optional
T = TypeVar("T", covariant=True)
H = TypeVar("H")
G = TypeVar("G")
class Mappable(Protocol[T]):
def map(self, f: Callable[[T], G]) -> 'Mappable[G]':
...
def map_int_elts_to_str(x: Mappable[int]):
y = x.map(str)
if TYPE_CHECKING:
reveal_locals()
return y
class MyList(List[H]):
def map(self, f: Callable[[H], G]) -> MyList[G]:
ret = MyList[G]()
append = MyList.append
for each in self:
append(ret, f(each))
return ret
def test() -> None:
z = map_int_elts_to_str(MyList([1, 2, 3]))
k = z[0]
if TYPE_CHECKING:
reveal_locals()