-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathextended_ast.py
55 lines (43 loc) · 1.23 KB
/
extended_ast.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
import ast
import typing as t
class ExDict(ast.Dict):
def __init__(
self,
keys: t.List[ast.expr],
values: t.List[ast.expr],
ctx: t.Union[ast.Store, ast.Load],
lineno=None,
col_offset=None,
):
super().__init__()
self.keys = keys
self.values = values
self.ctx = ctx
if lineno:
self.lineno = lineno
if col_offset:
self.col_offset = col_offset
_fields = ('keys', 'values', 'ctx')
class ConstantMapping(ast.Constant):
def __init__(self, value, lineno=None, col_offset=None):
super().__init__()
self.value = value
self.lineno = lineno
self.col_offset = col_offset
class AssignExpr(ast.Assign):
def __init__(self,
target: ast.expr,
value: ast.expr,
lineno: int = None,
col_offset: int = None):
super().__init__()
self.value = value
self.targets = [target]
self.lineno = lineno
self.col_offset = col_offset
@property
def target(self):
return self.targets[0]
@target.setter
def target(self, value):
self.targets[0] = value