-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
191 lines (147 loc) · 4.14 KB
/
__init__.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from typing import Generic, TypeVar
import src.pypotage as pypotage
import logging
import traceback
if __name__ == "__main__":
di = pypotage.cook(logging.Logger)
print(pypotage.is_cooked(di))
print(pypotage.is_cooked(logging.Logger))
print(pypotage.get_order(di))
try:
print(pypotage.get_order(1))
exit(-1)
except:
traceback.print_exc()
ingr = pypotage.get_order(di)
print(ingr.is_prepared())
print(type(di))
@pypotage.prepare(
pypotage.lazy,
pypotage.no_call)
def prepare2() -> logging.Logger:
print("Hello, World 2!")
logger = logging.getLogger("Test2")
logger.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
print(ingr.is_prepared())
print(type(di))
print("----------------")
print(di)
print("----------------")
print(di)
@pypotage.prepare(
pypotage.lazy)
def prepare1() -> logging.Logger:
print("Hello, World 1!")
logger = logging.getLogger("Test1")
logger.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
print(di)
prepare1().info("Hello, World 1!")
@pypotage.prepare(
pypotage.lazy,
pypotage.primary,
pypotage.no_call,
pypotage.order(1),
pypotage.id("logger"),
pypotage.type(logging.Logger)
)
class TestClass:
logger = pypotage.cook(logging.Logger)
def do_test(self):
self.logger.info("Test")
x = TestClass()
x.do_test()
@pypotage.prepare(
pypotage.lazy
)
def prepare3() -> logging.Logger:
print("Hello, World 3!")
logger = logging.getLogger("Test3")
logger.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
x.do_test()
ints = pypotage.cook(list[int])
print(ints)
@pypotage.prepare
def test():
return 1
print(pypotage.cook(int))
print(ints)
print(ints)
@pypotage.prepare
def test():
return 2
print(ints)
a = pypotage.cook(int)
def test2(aLogger = pypotage.cook(logging.Logger)):
print("Logging from %s" % aLogger)
test2()
@pypotage.prepare
def test3():
logger = logging.getLogger("Test4")
logger.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
test2()
print(pypotage.cook(list[logging.Logger]))
print(pypotage.cook(logging.Logger, "logger"))
_T = TypeVar("_T")
class Test(Generic[_T]): ...
@pypotage.prepare(
pypotage.type(Test[int])
)
def test1():
return 1
@pypotage.prepare(
pypotage.type(Test[str])
)
def test1():
return "1"
@pypotage.prepare(
pypotage.type(Test)
)
def test1():
return True
@pypotage.prepare(
pypotage.type(Test[int])
)
def test1():
return 2
print(pypotage.cook(list[Test[int]]), pypotage.cook(list[Test]), pypotage.cook(list[Test[str]]))
cook = pypotage.cook(Test[int])
print(type(pypotage.unpack(cook)), type(cook))
print("----------------")
print(di)
print("----------------")
print(di)
print(di)
x.do_test()
print(ints)
j = pypotage.cook(int)
print(j)
@pypotage.prepare
def test():
return 3
print(j)
print(pypotage.cook(int))
print(ints)