-
Notifications
You must be signed in to change notification settings - Fork 1
/
new.py
78 lines (54 loc) · 1.55 KB
/
new.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
from __future__ import annotations
from typing import TypeVar
from flywheel import wrap_endpoint
from flywheel.fn.endpoint import FnCollectEndpoint
from flywheel.globals import global_collect
from flywheel.overloads import SimpleOverload
from flywheel.scoped import scoped_collect
from typing_extensions import reveal_type
T = TypeVar("T")
class test():
sim = SimpleOverload("sim")
@wrap_endpoint
@classmethod
def normal(cls, type: type[T]):
yield cls.sim.hold(type)
def shape(type: type[T]) -> T: ...
return shape
def call(self, type: type[T]) -> T:
for selection in self.normal.select():
if not selection.harvest(self.sim, type):
continue
selection.complete()
return selection(type)
@FnCollectEndpoint
def normal_bare(type: type[T]):
yield test.sim.hold(type)
def shape(type: type[T]) -> T: ...
return shape
reveal_type(test.normal)
reveal_type(test.normal(int))
reveal_type(normal_bare)
reveal_type(normal_bare(int))
@global_collect
@test.normal(type=int)
def s(type: type[int]):
return 1
@global_collect
@test.normal(type=str)
def s1(type: type[str]):
return "111"
a = test().call(int)
b = test().call(str)
print(a)
print(b)
class test1(m := scoped_collect.locals().target, static=True):
@m.impl(test.normal(type=int))
def s(self, type: type[int]):
return 2
with test1.collector.lookup_scope():
#print([i.fn_implements for i in iter_layout()])
a = test().call(int)
b = test().call(str)
print(a)
print(b)