Debian Codegraph @

test-data/unit/fine-grained-cycles.test

raw
1 -- Test cases for fine-grained incremental checking and import cycles
2 --
3 -- The comment at the top of fine-grained.test explains how these tests
4 -- work.
5
6 [case testFunctionSelfReferenceThroughImportCycle]
7 import a
8 [file a.py]
9 from b import f
10 [file b.py]
11 import a
12
13 def f() -> None:
14 a.f()
15 [file b.py.2]
16 import a
17
18 def f(x: int) -> None:
19 a.f()
20 [out]
21 ==
22 b.py:4: error: Missing positional argument "x" in call to "f"
23
24 [case testClassSelfReferenceThroughImportCycle]
25 import a
26 [file a.py]
27 from b import A
28 [file b.py]
29 import a
30
31 class A:
32 def g(self) -> None: pass
33
34 def f() -> None:
35 a.A().g()
36 [file b.py.2]
37 import a
38
39 class A:
40 def g(self, x: int) -> None: pass
41
42 def f() -> None:
43 a.A().g()
44 [out]
45 ==
46 b.py:7: error: Missing positional argument "x" in call to "g" of "A"
47
48 [case testAnnotationSelfReferenceThroughImportCycle]
49 import a
50 [file a.py]
51 from b import A
52 [file b.py]
53 import a
54
55 x: a.A
56
57 class A:
58 def g(self) -> None: pass
59
60 def f() -> None:
61 x.g()
62 [file b.py.2]
63 import a
64
65 x: a.A
66
67 class A:
68 def g(self, x: int) -> None: pass
69
70 def f() -> None:
71 x.g()
72 [out]
73 ==
74 b.py:9: error: Missing positional argument "x" in call to "g" of "A"
75
76 [case testModuleSelfReferenceThroughImportCycle]
77 import a
78 [file a.py]
79 import b
80 [file b.py]
81 import a
82
83 def f() -> None:
84 a.b.f()
85 [file b.py.2]
86 import a
87
88 def f(x: int) -> None:
89 a.b.f()
90 [out]
91 ==
92 b.py:4: error: Missing positional argument "x" in call to "f"
93
94 [case testVariableSelfReferenceThroughImportCycle]
95 import a
96 [file a.py]
97 from b import x
98 [file b.py]
99 import a
100
101 x: int
102
103 def f() -> None:
104 a.x = 1
105 [file b.py.2]
106 import a
107
108 x: str
109
110 def f() -> None:
111 a.x = 1
112 [out]
113 ==
114 b.py:6: error: Incompatible types in assignment (expression has type "int", variable has type "str")
115
116 [case testReferenceToTypeThroughCycle]
117 import a
118
119 [file a.py]
120 from b import C
121
122 def f() -> C: pass
123
124 [file b.py]
125 import a
126
127 class C:
128 def g(self) -> None: pass
129
130 def h() -> None:
131 c = a.f()
132 c.g()
133
134 [file b.py.2]
135 import a
136
137 class C:
138 def g(self, x: int) -> None: pass
139
140 def h() -> None:
141 c = a.f()
142 c.g()
143
144 [out]
145 ==
146 b.py:8: error: Missing positional argument "x" in call to "g" of "C"
147
148 [case testReferenceToTypeThroughCycleAndDeleteType]
149 import a
150
151 [file a.py]
152 from b import C
153
154 def f() -> C: pass
155
156 [file b.py]
157 import a
158
159 class C:
160 def g(self) -> None: pass
161
162 def h() -> None:
163 c = a.f()
164 c.g()
165
166 [file b.py.2]
167 import a
168
169 def h() -> None:
170 c = a.f()
171 c.g()
172
173 [out]
174 ==
175 a.py:1: error: Module "b" has no attribute "C"
176
177 [case testReferenceToTypeThroughCycleAndReplaceWithFunction]
178
179 import a
180
181 [file a.py]
182 from b import C
183
184 def f() -> C: pass
185
186 [file b.py]
187 import a
188
189 class C:
190 def g(self) -> None: pass
191
192 def h() -> None:
193 c = a.f()
194 c.g()
195
196 [file b.py.2]
197 import a
198
199 def C() -> int: pass
200
201 def h() -> None:
202 c = a.f()
203 c.g()
204
205 [out]
206 ==
207 a.py:3: error: Function "b.C" is not valid as a type
208 a.py:3: note: Perhaps you need "Callable[...]" or a callback protocol?
209 b.py:7: error: C? has no attribute "g"
210
211 -- TODO: More import cycle:
212 --
213 -- * "from x import y" through cycle
214 -- * "from x import *" through cycle
215 -- * "Cls.module" though cycle
216 -- * TypeVar
217 -- * type alias
218 -- * all kinds of reference deleted
219 -- * all kinds of reference rebound to different kind
220 --
221 -- etc.