Coverage for pysource_codegen/static_type_info.py: 100%
7 statements
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-13 21:17 +0200
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-13 21:17 +0200
1import ast
2import sys
4from .types import BuiltinNodeType
5from .types import NodeType
6from .types import UnionNodeType
8assert sys.version_info >= (3, 8)
10type_infos = {
11 "Delete": NodeType(
12 fields={"targets": ("_deleteTargets", "*")}, ast_type=ast.Delete
13 ),
14 "expr": UnionNodeType(
15 options=[
16 "BoolOp",
17 "NamedExpr",
18 "BinOp",
19 "UnaryOp",
20 "Lambda",
21 "IfExp",
22 "Dict",
23 "Set",
24 "ListComp",
25 "SetComp",
26 "DictComp",
27 "GeneratorExp",
28 "Await",
29 "Yield",
30 "YieldFrom",
31 "Compare",
32 "Call",
33 "FormattedValue",
34 "JoinedStr",
35 "Constant",
36 "Attribute",
37 "Subscript",
38 "Starred",
39 "Name",
40 "List",
41 "Tuple",
42 ]
43 ),
44 "BoolOp": NodeType(
45 fields={"op": ("boolop", ""), "values": ("expr", "*")}, ast_type=ast.BoolOp
46 ),
47 "boolop": UnionNodeType(options=["And", "Or"]),
48 "And": NodeType(fields={}, ast_type=ast.And),
49 "Or": NodeType(fields={}, ast_type=ast.Or),
50 "NamedExpr": NodeType(
51 fields={"target": ("expr", ""), "value": ("expr", "")}, ast_type=ast.NamedExpr
52 ),
53 "BinOp": NodeType(
54 fields={"left": ("expr", ""), "op": ("operator", ""), "right": ("expr", "")},
55 ast_type=ast.BinOp,
56 ),
57 "operator": UnionNodeType(
58 options=[
59 "Add",
60 "Sub",
61 "Mult",
62 "MatMult",
63 "Div",
64 "Mod",
65 "Pow",
66 "LShift",
67 "RShift",
68 "BitOr",
69 "BitXor",
70 "BitAnd",
71 "FloorDiv",
72 ]
73 ),
74 "Add": NodeType(fields={}, ast_type=ast.Add),
75 "Sub": NodeType(fields={}, ast_type=ast.Sub),
76 "Mult": NodeType(fields={}, ast_type=ast.Mult),
77 "MatMult": NodeType(fields={}, ast_type=ast.MatMult),
78 "Div": NodeType(fields={}, ast_type=ast.Div),
79 "Mod": NodeType(fields={}, ast_type=ast.Mod),
80 "Pow": NodeType(fields={}, ast_type=ast.Pow),
81 "LShift": NodeType(fields={}, ast_type=ast.LShift),
82 "RShift": NodeType(fields={}, ast_type=ast.RShift),
83 "BitOr": NodeType(fields={}, ast_type=ast.BitOr),
84 "BitXor": NodeType(fields={}, ast_type=ast.BitXor),
85 "BitAnd": NodeType(fields={}, ast_type=ast.BitAnd),
86 "FloorDiv": NodeType(fields={}, ast_type=ast.FloorDiv),
87 "UnaryOp": NodeType(
88 fields={"op": ("unaryop", ""), "operand": ("expr", "")}, ast_type=ast.UnaryOp
89 ),
90 "unaryop": UnionNodeType(options=["Invert", "Not", "UAdd", "USub"]),
91 "Invert": NodeType(fields={}, ast_type=ast.Invert),
92 "Not": NodeType(fields={}, ast_type=ast.Not),
93 "UAdd": NodeType(fields={}, ast_type=ast.UAdd),
94 "USub": NodeType(fields={}, ast_type=ast.USub),
95 "Lambda": NodeType(
96 fields={"args": ("arguments", ""), "body": ("expr", "")}, ast_type=ast.Lambda
97 ),
98 "arguments": NodeType(
99 fields={
100 "posonlyargs": ("arg", "*"),
101 "args": ("arg", "*"),
102 "vararg": ("arg", "?"),
103 "kwonlyargs": ("arg", "*"),
104 "kw_defaults": ("expr", "*"),
105 "kwarg": ("arg", "?"),
106 "defaults": ("expr", "*"),
107 },
108 ast_type=ast.arguments,
109 ),
110 "arg": NodeType(
111 fields={
112 "arg": ("identifier", ""),
113 "annotation": ("expr", "?"),
114 "type_comment": ("string", "?"),
115 },
116 ast_type=ast.arg,
117 ),
118 "identifier": BuiltinNodeType(kind="identifier"),
119 "string": BuiltinNodeType(kind="string"),
120 "IfExp": NodeType(
121 fields={"test": ("expr", ""), "body": ("expr", ""), "orelse": ("expr", "")},
122 ast_type=ast.IfExp,
123 ),
124 "Dict": NodeType(
125 fields={"keys": ("expr", "*"), "values": ("expr", "*")}, ast_type=ast.Dict
126 ),
127 "Set": NodeType(fields={"elts": ("expr", "*")}, ast_type=ast.Set),
128 "ListComp": NodeType(
129 fields={"elt": ("expr", ""), "generators": ("comprehension", "*")},
130 ast_type=ast.ListComp,
131 ),
132 "comprehension": NodeType(
133 fields={
134 "target": ("expr", ""),
135 "iter": ("expr", ""),
136 "ifs": ("expr", "*"),
137 "is_async": ("int", ""),
138 },
139 ast_type=ast.comprehension,
140 ),
141 "int": BuiltinNodeType(kind="int"),
142 "SetComp": NodeType(
143 fields={"elt": ("expr", ""), "generators": ("comprehension", "*")},
144 ast_type=ast.SetComp,
145 ),
146 "DictComp": NodeType(
147 fields={
148 "key": ("expr", ""),
149 "value": ("expr", ""),
150 "generators": ("comprehension", "*"),
151 },
152 ast_type=ast.DictComp,
153 ),
154 "GeneratorExp": NodeType(
155 fields={"elt": ("expr", ""), "generators": ("comprehension", "*")},
156 ast_type=ast.GeneratorExp,
157 ),
158 "Await": NodeType(fields={"value": ("expr", "")}, ast_type=ast.Await),
159 "Yield": NodeType(fields={"value": ("expr", "?")}, ast_type=ast.Yield),
160 "YieldFrom": NodeType(fields={"value": ("expr", "")}, ast_type=ast.YieldFrom),
161 "Compare": NodeType(
162 fields={
163 "left": ("expr", ""),
164 "ops": ("cmpop", "*"),
165 "comparators": ("expr", "*"),
166 },
167 ast_type=ast.Compare,
168 ),
169 "cmpop": UnionNodeType(
170 options=["Eq", "NotEq", "Lt", "LtE", "Gt", "GtE", "Is", "IsNot", "In", "NotIn"]
171 ),
172 "Eq": NodeType(fields={}, ast_type=ast.Eq),
173 "NotEq": NodeType(fields={}, ast_type=ast.NotEq),
174 "Lt": NodeType(fields={}, ast_type=ast.Lt),
175 "LtE": NodeType(fields={}, ast_type=ast.LtE),
176 "Gt": NodeType(fields={}, ast_type=ast.Gt),
177 "GtE": NodeType(fields={}, ast_type=ast.GtE),
178 "Is": NodeType(fields={}, ast_type=ast.Is),
179 "IsNot": NodeType(fields={}, ast_type=ast.IsNot),
180 "In": NodeType(fields={}, ast_type=ast.In),
181 "NotIn": NodeType(fields={}, ast_type=ast.NotIn),
182 "Call": NodeType(
183 fields={
184 "func": ("expr", ""),
185 "args": ("expr", "*"),
186 "keywords": ("keyword", "*"),
187 },
188 ast_type=ast.Call,
189 ),
190 "keyword": NodeType(
191 fields={"arg": ("identifier", "?"), "value": ("expr", "")}, ast_type=ast.keyword
192 ),
193 "FormattedValue": NodeType(
194 fields={
195 "value": ("expr", ""),
196 "conversion": ("int", "?"),
197 "format_spec": ("expr", "?"),
198 },
199 ast_type=ast.FormattedValue,
200 ),
201 "JoinedStr": NodeType(fields={"values": ("expr", "*")}, ast_type=ast.JoinedStr),
202 "Constant": NodeType(
203 fields={"value": ("constant", ""), "kind": ("string", "?")},
204 ast_type=ast.Constant,
205 ),
206 "constant": BuiltinNodeType(kind="constant"),
207 "Attribute": NodeType(
208 fields={
209 "value": ("expr", ""),
210 "attr": ("identifier", ""),
211 "ctx": ("expr_context", ""),
212 },
213 ast_type=ast.Attribute,
214 ),
215 "expr_context": UnionNodeType(options=["Load", "Store", "Del"]),
216 "Load": NodeType(fields={}, ast_type=ast.Load),
217 "Store": NodeType(fields={}, ast_type=ast.Store),
218 "Del": NodeType(fields={}, ast_type=ast.Del),
219 "Subscript": NodeType(
220 fields={
221 "value": ("expr", ""),
222 "slice": ("slice", ""),
223 "ctx": ("expr_context", ""),
224 },
225 ast_type=ast.Subscript,
226 ),
227 "Starred": NodeType(
228 fields={"value": ("expr", ""), "ctx": ("expr_context", "")},
229 ast_type=ast.Starred,
230 ),
231 "Name": NodeType(
232 fields={"id": ("identifier", ""), "ctx": ("expr_context", "")},
233 ast_type=ast.Name,
234 ),
235 "List": NodeType(
236 fields={"elts": ("expr", "*"), "ctx": ("expr_context", "")}, ast_type=ast.List
237 ),
238 "Tuple": NodeType(
239 fields={"elts": ("expr", "*"), "ctx": ("expr_context", "")}, ast_type=ast.Tuple
240 ),
241 "slice": UnionNodeType(options=["Slice", "ExtSlice", "Index"]),
242 "Slice": NodeType(
243 fields={"lower": ("expr", "?"), "upper": ("expr", "?"), "step": ("expr", "?")},
244 ast_type=ast.Slice,
245 ),
246 "ExtSlice": NodeType(
247 fields={"dims": ("slice", "*")},
248 ast_type=ast.ExtSlice,
249 ),
250 "Index": NodeType(
251 fields={"value": ("expr", "")},
252 ast_type=ast.Index,
253 ),
254 "_deleteTargets": UnionNodeType(options=["Name", "Attribute", "Subscript"]),
255 "Module": NodeType(
256 fields={"body": ("stmt", "*"), "type_ignores": ("type_ignore", "*")},
257 ast_type=ast.Module,
258 ),
259 "stmt": UnionNodeType(
260 options=[
261 "FunctionDef",
262 "AsyncFunctionDef",
263 "ClassDef",
264 "Return",
265 "Delete",
266 "Assign",
267 "AugAssign",
268 "AnnAssign",
269 "For",
270 "AsyncFor",
271 "While",
272 "If",
273 "With",
274 "AsyncWith",
275 "Raise",
276 "Try",
277 "Assert",
278 "Import",
279 "ImportFrom",
280 "Global",
281 "Nonlocal",
282 "Expr",
283 "Pass",
284 "Break",
285 "Continue",
286 ]
287 ),
288 "FunctionDef": NodeType(
289 fields={
290 "name": ("identifier", ""),
291 "args": ("arguments", ""),
292 "body": ("stmt", "*"),
293 "decorator_list": ("expr", "*"),
294 "returns": ("expr", "?"),
295 "type_comment": ("string", "?"),
296 },
297 ast_type=ast.FunctionDef,
298 ),
299 "AsyncFunctionDef": NodeType(
300 fields={
301 "name": ("identifier", ""),
302 "args": ("arguments", ""),
303 "body": ("stmt", "*"),
304 "decorator_list": ("expr", "*"),
305 "returns": ("expr", "?"),
306 "type_comment": ("string", "?"),
307 },
308 ast_type=ast.AsyncFunctionDef,
309 ),
310 "ClassDef": NodeType(
311 fields={
312 "name": ("identifier", ""),
313 "bases": ("expr", "*"),
314 "keywords": ("keyword", "*"),
315 "body": ("stmt", "*"),
316 "decorator_list": ("expr", "*"),
317 },
318 ast_type=ast.ClassDef,
319 ),
320 "Return": NodeType(fields={"value": ("expr", "?")}, ast_type=ast.Return),
321 "Assign": NodeType(
322 fields={
323 "targets": ("expr", "*"),
324 "value": ("expr", ""),
325 "type_comment": ("string", "?"),
326 },
327 ast_type=ast.Assign,
328 ),
329 "AugAssign": NodeType(
330 fields={"target": ("expr", ""), "op": ("operator", ""), "value": ("expr", "")},
331 ast_type=ast.AugAssign,
332 ),
333 "AnnAssign": NodeType(
334 fields={
335 "target": ("expr", ""),
336 "annotation": ("expr", ""),
337 "value": ("expr", "?"),
338 "simple": ("int", ""),
339 },
340 ast_type=ast.AnnAssign,
341 ),
342 "For": NodeType(
343 fields={
344 "target": ("expr", ""),
345 "iter": ("expr", ""),
346 "body": ("stmt", "*"),
347 "orelse": ("stmt", "*"),
348 "type_comment": ("string", "?"),
349 },
350 ast_type=ast.For,
351 ),
352 "AsyncFor": NodeType(
353 fields={
354 "target": ("expr", ""),
355 "iter": ("expr", ""),
356 "body": ("stmt", "*"),
357 "orelse": ("stmt", "*"),
358 "type_comment": ("string", "?"),
359 },
360 ast_type=ast.AsyncFor,
361 ),
362 "While": NodeType(
363 fields={"test": ("expr", ""), "body": ("stmt", "*"), "orelse": ("stmt", "*")},
364 ast_type=ast.While,
365 ),
366 "If": NodeType(
367 fields={"test": ("expr", ""), "body": ("stmt", "*"), "orelse": ("stmt", "*")},
368 ast_type=ast.If,
369 ),
370 "With": NodeType(
371 fields={
372 "items": ("withitem", "*"),
373 "body": ("stmt", "*"),
374 "type_comment": ("string", "?"),
375 },
376 ast_type=ast.With,
377 ),
378 "withitem": NodeType(
379 fields={"context_expr": ("expr", ""), "optional_vars": ("expr", "?")},
380 ast_type=ast.withitem,
381 ),
382 "AsyncWith": NodeType(
383 fields={
384 "items": ("withitem", "*"),
385 "body": ("stmt", "*"),
386 "type_comment": ("string", "?"),
387 },
388 ast_type=ast.AsyncWith,
389 ),
390 "Raise": NodeType(
391 fields={"exc": ("expr", "?"), "cause": ("expr", "?")}, ast_type=ast.Raise
392 ),
393 "Try": NodeType(
394 fields={
395 "body": ("stmt", "*"),
396 "handlers": ("excepthandler", "*"),
397 "orelse": ("stmt", "*"),
398 "finalbody": ("stmt", "*"),
399 },
400 ast_type=ast.Try,
401 ),
402 "excepthandler": UnionNodeType(options=["ExceptHandler"]),
403 "ExceptHandler": NodeType(
404 fields={
405 "type": ("expr", "?"),
406 "name": ("identifier", "?"),
407 "body": ("stmt", "*"),
408 },
409 ast_type=ast.ExceptHandler,
410 ),
411 "Assert": NodeType(
412 fields={"test": ("expr", ""), "msg": ("expr", "?")}, ast_type=ast.Assert
413 ),
414 "Import": NodeType(fields={"names": ("alias", "*")}, ast_type=ast.Import),
415 "alias": NodeType(
416 fields={"name": ("identifier", ""), "asname": ("identifier", "?")},
417 ast_type=ast.alias,
418 ),
419 "ImportFrom": NodeType(
420 fields={
421 "module": ("identifier", "?"),
422 "names": ("alias", "*"),
423 "level": ("int", "?"),
424 },
425 ast_type=ast.ImportFrom,
426 ),
427 "Global": NodeType(fields={"names": ("identifier", "*")}, ast_type=ast.Global),
428 "Nonlocal": NodeType(fields={"names": ("identifier", "*")}, ast_type=ast.Nonlocal),
429 "Expr": NodeType(fields={"value": ("expr", "")}, ast_type=ast.Expr),
430 "Pass": NodeType(fields={}, ast_type=ast.Pass),
431 "Break": NodeType(fields={}, ast_type=ast.Break),
432 "Continue": NodeType(fields={}, ast_type=ast.Continue),
433 "type_ignore": UnionNodeType(options=["TypeIgnore"]),
434 "TypeIgnore": NodeType(
435 fields={"lineno": ("int", ""), "tag": ("string", "")}, ast_type=ast.TypeIgnore
436 ),
437}