Debian Codegraph @

test-data/unit/deps-generics.test

raw
1 -- Test cases for generating fine-grained dependencies involving generics.
2 --
3 -- The dependencies are used for fined-grained incremental checking.
4 --
5 -- See the comment at the top of deps.test for more documentation.
6
7 [case testGenericFunction]
8 from typing import TypeVar
9
10 T = TypeVar('T')
11
12 class A: pass
13
14 def f(x: T) -> T:
15 y: T
16 z: A
17 return x
18 [out]
19 <m.A> -> m.A, m.f
20 <m.T> -> <m.f>, m.f
21
22 [case testGenericClass]
23 from typing import TypeVar, Generic
24
25 T = TypeVar('T')
26
27 class A(Generic[T]): pass
28 class B: pass
29
30 def f() -> None:
31 a: A[B]
32 [out]
33 <m.A> -> m.A, m.f
34 <m.B> -> m.B, m.f
35 <m.T> -> m.A
36
37 [case testGenericClassWithMembers]
38 from typing import TypeVar, Generic
39
40 T = TypeVar('T')
41
42 class A(Generic[T]):
43 def g(self, a: T) -> None:
44 self.x = a
45 def f(self) -> T:
46 return self.x
47 [out]
48 <m.A.x> -> m.A.f, m.A.g
49 <m.A> -> m.A
50 <m.T> -> <m.A.f>, <m.A.g>, <m.A.x>, m.A, m.A.f, m.A.g
51
52 [case testGenericClassInit]
53 from typing import TypeVar, Generic
54
55 T = TypeVar('T')
56
57 class A(Generic[T]):
58 def __init__(self, a: T) -> None:
59 self.x = a
60
61 class B: pass
62
63 def f() -> None:
64 a = A(B())
65 [out]
66 <m.A.__init__> -> m.f
67 <m.A.__new__> -> m.f
68 <m.A.x> -> m.A.__init__
69 <m.A> -> m.A, m.f
70 <m.B.__init__> -> m.f
71 <m.B.__new__> -> m.f
72 <m.B> -> m.B, m.f
73 <m.T> -> <m.A.__init__>, <m.A.x>, m.A, m.A.__init__
74
75 [case testGenericMethod]
76 from typing import TypeVar
77
78 T = TypeVar('T')
79
80 class A:
81 def f(self, x: T) -> T:
82 return x
83 [out]
84 <m.A> -> m.A
85 <m.T> -> <m.A.f>, m.A.f
86
87 [case testGenericBaseClass]
88 from typing import TypeVar, Generic
89
90 T = TypeVar('T')
91
92 class A(Generic[T]): pass
93 class B(A[C]): pass
94 class C: pass
95 [out]
96 <m.A.(abstract)> -> <m.B.__init__>, m
97 <m.A.__init__> -> <m.B.__init__>
98 <m.A.__new__> -> <m.B.__new__>
99 <m.A> -> m, m.A, m.B
100 <m.B> -> m.B
101 <m.C> -> m, m.B, m.C
102 <m.T> -> m.A
103
104 [case testGenericBaseClass2]
105 from typing import TypeVar, Generic
106
107 T = TypeVar('T')
108
109 class A(Generic[T]): pass
110 class B(A[T]): pass
111 [out]
112 <m.A.(abstract)> -> <m.B.__init__>, m
113 <m.A.__init__> -> <m.B.__init__>
114 <m.A.__new__> -> <m.B.__new__>
115 <m.A> -> m, m.A, m.B
116 <m.B> -> m.B
117 <m.T> -> m, m.A, m.B
118
119 [case testTypeVarBound]
120 from typing import TypeVar, Tuple
121
122 class A: pass
123 class B: pass
124
125 T = TypeVar('T', bound=Tuple[A, B])
126
127 def f(x: T) -> T:
128 return x
129 [builtins fixtures/tuple.pyi]
130 [out]
131 <m.A> -> <m.T>, <m.f>, m, m.A, m.f
132 <m.B> -> <m.T>, <m.f>, m, m.B, m.f
133 <m.T> -> <m.f>, m.f
134
135 [case testTypeVarBoundOperations]
136 from typing import TypeVar, Tuple
137
138 class A:
139 def f(self) -> None: pass
140 def __add__(self, other: int) -> int: pass
141
142 T = TypeVar('T', bound=A)
143
144 def f(x: T) -> None:
145 x.f()
146 x + 1
147 [out]
148 <m.A.__add__> -> m.f
149 <m.A.f> -> m.f
150 <m.A> -> <m.T>, <m.f>, m, m.A, m.f
151 <m.T> -> <m.f>, m.f
152
153 [case testTypeVarValues]
154 from typing import TypeVar
155 class A: pass
156 class B: pass
157 class C: pass
158 class D: pass
159 T = TypeVar('T', A, B)
160 S = TypeVar('S', C, D)
161
162 def f(x: T, y: S) -> S:
163 pass
164 [out]
165 <m.A> -> <m.T>, <m.f>, m, m.A, m.f
166 <m.B> -> <m.T>, <m.f>, m, m.B, m.f
167 <m.C> -> <m.S>, <m.f>, m, m.C, m.f
168 <m.D> -> <m.S>, <m.f>, m, m.D, m.f
169 <m.S> -> <m.f>, m.f
170 <m.T> -> <m.f>, m.f
171
172 [case testTypeVarValuesMethod]
173 from typing import TypeVar, Generic
174 class C: pass
175 class D: pass
176 S = TypeVar('S', C, D)
177
178 class G(Generic[S]):
179 def f(self) -> S:
180 pass
181 [out]
182 <m.C> -> <m.G.f>, <m.S>, m, m.C, m.G.f
183 <m.D> -> <m.G.f>, <m.S>, m, m.D, m.G.f
184 <m.G> -> m.G
185 <m.S> -> <m.G.f>, m.G, m.G.f
186
187 [case testTypeVarValuesMethodAttr]
188 from typing import TypeVar, Generic
189 class A:
190 x: int
191 class B:
192 x: int
193 T = TypeVar('T', A, B)
194
195 class G(Generic[T]):
196 def f(self, x: T) -> None:
197 x.x
198 [out]
199 <m.A.x> -> m.G.f
200 <m.A> -> <m.G.f>, <m.T>, m, m.A, m.G.f
201 <m.B.x> -> m.G.f
202 <m.B> -> <m.G.f>, <m.T>, m, m.B, m.G.f
203 <m.G> -> m.G
204 <m.T> -> <m.G.f>, m.G, m.G.f