1
1
from lazy_object_proxy import Proxy
2
2
from lazy_load import lazy , lz , lazy_func , lf , ℒ , lazy_class , lc , force_eval , fe
3
3
4
-
5
- def test_aliases ():
4
+ def test_aliases () -> None :
6
5
assert lazy is lz
7
6
8
7
assert lazy_func is lf
@@ -12,9 +11,9 @@ def test_aliases():
12
11
13
12
assert force_eval is fe
14
13
15
- def test_lazy_simple_expression_evaluation ():
14
+ def test_lazy_simple_expression_evaluation () -> None :
16
15
evaluated = False
17
- def add (x , y ) :
16
+ def add (x : int , y : int ) -> int :
18
17
nonlocal evaluated
19
18
evaluated = True
20
19
return x + y
@@ -26,9 +25,9 @@ def add(x, y):
26
25
assert evaluated
27
26
assert isinstance (res , int )
28
27
29
- def test_lazy_function_with_eagle_argument_evaluation ():
28
+ def test_lazy_function_with_eagle_argument_evaluation () -> None :
30
29
evaluated = False
31
- def add (x , y ) :
30
+ def add (x : int , y : int ) -> int :
32
31
nonlocal evaluated
33
32
evaluated = True
34
33
return x + y
@@ -40,9 +39,9 @@ def add(x, y):
40
39
assert evaluated
41
40
assert isinstance (res , int )
42
41
43
- def test_lazy_function_evaluation ():
42
+ def test_lazy_function_evaluation () -> None :
44
43
evaluated = False
45
- def add (x , y ) :
44
+ def add (x : int , y : int ) -> int :
46
45
nonlocal evaluated
47
46
evaluated = True
48
47
return x + y
@@ -55,11 +54,11 @@ def add(x, y):
55
54
assert evaluated
56
55
assert isinstance (res , int )
57
56
58
- def test_lazy_function_decorator ():
57
+ def test_lazy_function_decorator () -> None :
59
58
evaluated = False
60
59
61
60
@lazy_func
62
- def lazy_add (x , y ) :
61
+ def lazy_add (x : int , y : int ) -> int :
63
62
nonlocal evaluated
64
63
evaluated = True
65
64
return x + y
@@ -71,34 +70,34 @@ def lazy_add(x, y):
71
70
assert evaluated
72
71
assert isinstance (res , int )
73
72
74
- def test_lazy_class ():
73
+ def test_lazy_class () -> None :
75
74
evaluated = False
76
75
77
76
@lazy_class
78
77
class LazyClass :
79
- def __init__ (self , n ):
78
+ def __init__ (self , n : int ):
80
79
self ._n = n
81
80
82
- def add (self , m ) -> int :
81
+ def add (self , m : int ) -> int :
83
82
nonlocal evaluated
84
83
evaluated = True
85
84
return self ._n + m
86
85
87
- def sub (self , m ) -> None :
86
+ def sub (self , m : int ) -> None :
88
87
# Return type is None: This function should not be lazy evaluated
89
88
nonlocal evaluated
90
89
evaluated = True
91
- return self ._n - m
90
+ return self ._n - m # type: ignore
92
91
93
92
@lazy_func
94
- def mul (self , m ) -> None :
93
+ def mul (self , m : int ) -> None :
95
94
# Return type is None: This function should not be lazy evaluated;
96
95
# BUT there is the decorater: it makes the function lazy
97
96
nonlocal evaluated
98
97
evaluated = True
99
- return self ._n * m
98
+ return self ._n * m # type: ignore
100
99
101
- def _div (self , m ) -> int :
100
+ def _div (self , m : int ) -> int :
102
101
# Non-public functions are never made lazy by lazy_class
103
102
nonlocal evaluated
104
103
evaluated = True
@@ -114,13 +113,13 @@ def _div(self, m) -> int:
114
113
assert isinstance (res , int )
115
114
116
115
evaluated = False
117
- res = lazy_obj .sub (2 )
116
+ res = lazy_obj .sub (2 ) # type: ignore
118
117
assert not isinstance (res , Proxy )
119
118
assert evaluated
120
119
assert res == - 1
121
120
122
121
evaluated = False
123
- res = lazy_obj .mul (2 )
122
+ res = lazy_obj .mul (2 ) # type: ignore
124
123
assert not evaluated
125
124
assert isinstance (res , Proxy )
126
125
assert res == 2
@@ -133,9 +132,9 @@ def _div(self, m) -> int:
133
132
assert evaluated
134
133
assert res == 1
135
134
136
- def test_force_eval_on_objects ():
135
+ def test_force_eval_on_objects () -> None :
137
136
evaluated = False
138
- def do_something (x , y ) :
137
+ def do_something (x : int , y : int ) -> int :
139
138
nonlocal evaluated
140
139
evaluated = True
141
140
return x + y
@@ -145,19 +144,19 @@ def do_something(x, y):
145
144
force_eval (res )
146
145
assert evaluated
147
146
148
- def test_force_eval_on_callables ():
147
+ def test_force_eval_on_callables () -> None :
149
148
evaluated = False
150
- def do_something ():
149
+ def do_something () -> None :
151
150
nonlocal evaluated
152
151
evaluated = True
153
152
do_something_lazy = ℒ [do_something ]
154
153
assert do_something_lazy is not do_something
155
154
assert fe (do_something_lazy ) is do_something
156
155
assert not evaluated
157
156
158
- def test_multiple_lazy_on_expression ():
157
+ def test_multiple_lazy_on_expression () -> None :
159
158
evaluated = False
160
- def add (x , y ) :
159
+ def add (x : int , y : int ) -> int :
161
160
nonlocal evaluated
162
161
evaluated = True
163
162
return x + y
@@ -178,9 +177,9 @@ def add(x, y):
178
177
assert res == 3
179
178
assert evaluated
180
179
181
- def test_multiple_lazy_onfunction ():
180
+ def test_multiple_lazy_onfunction () -> None :
182
181
evaluated = False
183
- def add (x , y ) :
182
+ def add (x : int , y : int ) -> int :
184
183
nonlocal evaluated
185
184
evaluated = True
186
185
return x + y
0 commit comments