@@ -97,6 +97,7 @@ class Node(Context):
97
97
line = - 1
98
98
column = - 1
99
99
100
+ # TODO: Move to Expression
100
101
literal = LITERAL_NO
101
102
literal_hash = None # type: Any
102
103
@@ -139,8 +140,9 @@ class Statement(Node):
139
140
class Expression (Node ):
140
141
"""An expression node."""
141
142
142
-
143
- # TODO: Union['NameExpr', 'TupleExpr', 'ListExpr', 'MemberExpr', 'IndexExpr']; see #1783.
143
+ # TODO:
144
+ # Lvalue = Union['NameExpr', 'MemberExpr', 'IndexExpr', 'SuperExpr', 'StarExpr'
145
+ # 'TupleExpr', 'ListExpr']; see #1783.
144
146
Lvalue = Expression
145
147
146
148
@@ -157,7 +159,7 @@ def fullname(self) -> str: pass
157
159
158
160
# NOTE: Can't use @abstractmethod, since many subclasses of Node
159
161
# don't implement serialize().
160
- def serialize (self ) -> Any :
162
+ def serialize (self ) -> JsonDict :
161
163
raise NotImplementedError ('Cannot serialize {} instance' .format (self .__class__ .__name__ ))
162
164
163
165
@classmethod
@@ -171,7 +173,7 @@ def deserialize(cls, data: JsonDict) -> 'SymbolNode':
171
173
raise NotImplementedError ('unexpected .class {}' .format (classname ))
172
174
173
175
174
- class MypyFile (SymbolNode , Statement ):
176
+ class MypyFile (SymbolNode ):
175
177
"""The abstract syntax tree of a single source file."""
176
178
177
179
# Module name ('__main__' for initial file)
@@ -591,7 +593,7 @@ def deserialize(cls, data: JsonDict) -> 'Decorator':
591
593
return dec
592
594
593
595
594
- class Var (SymbolNode , Statement ):
596
+ class Var (SymbolNode ):
595
597
"""A variable.
596
598
597
599
It can refer to global/local variable or a data attribute.
@@ -798,10 +800,10 @@ class OperatorAssignmentStmt(Statement):
798
800
"""Operator assignment statement such as x += 1"""
799
801
800
802
op = ''
801
- lvalue = None # type: Expression
803
+ lvalue = None # type: Lvalue
802
804
rvalue = None # type: Expression
803
805
804
- def __init__ (self , op : str , lvalue : Expression , rvalue : Expression ) -> None :
806
+ def __init__ (self , op : str , lvalue : Lvalue , rvalue : Expression ) -> None :
805
807
self .op = op
806
808
self .lvalue = lvalue
807
809
self .rvalue = rvalue
@@ -826,14 +828,14 @@ def accept(self, visitor: NodeVisitor[T]) -> T:
826
828
827
829
class ForStmt (Statement ):
828
830
# Index variables
829
- index = None # type: Expression
831
+ index = None # type: Lvalue
830
832
# Expression to iterate
831
833
expr = None # type: Expression
832
834
body = None # type: Block
833
835
else_body = None # type: Block
834
836
is_async = False # True if `async for ...` (PEP 492, Python 3.5)
835
837
836
- def __init__ (self , index : Expression , expr : Expression , body : Block ,
838
+ def __init__ (self , index : Lvalue , expr : Expression , body : Block ,
837
839
else_body : Block ) -> None :
838
840
self .index = index
839
841
self .expr = expr
@@ -865,9 +867,9 @@ def accept(self, visitor: NodeVisitor[T]) -> T:
865
867
866
868
867
869
class DelStmt (Statement ):
868
- expr = None # type: Expression
870
+ expr = None # type: Lvalue
869
871
870
- def __init__ (self , expr : Expression ) -> None :
872
+ def __init__ (self , expr : Lvalue ) -> None :
871
873
self .expr = expr
872
874
873
875
def accept (self , visitor : NodeVisitor [T ]) -> T :
@@ -940,11 +942,11 @@ def accept(self, visitor: NodeVisitor[T]) -> T:
940
942
941
943
class WithStmt (Statement ):
942
944
expr = None # type: List[Expression]
943
- target = None # type: List[Expression ]
945
+ target = None # type: List[Lvalue ]
944
946
body = None # type: Block
945
947
is_async = False # True if `async with ...` (PEP 492, Python 3.5)
946
948
947
- def __init__ (self , expr : List [Expression ], target : List [Expression ],
949
+ def __init__ (self , expr : List [Expression ], target : List [Lvalue ],
948
950
body : Block ) -> None :
949
951
self .expr = expr
950
952
self .target = target
@@ -1540,9 +1542,9 @@ class GeneratorExpr(Expression):
1540
1542
left_expr = None # type: Expression
1541
1543
sequences = None # type: List[Expression]
1542
1544
condlists = None # type: List[List[Expression]]
1543
- indices = None # type: List[Expression ]
1545
+ indices = None # type: List[Lvalue ]
1544
1546
1545
- def __init__ (self , left_expr : Expression , indices : List [Expression ],
1547
+ def __init__ (self , left_expr : Expression , indices : List [Lvalue ],
1546
1548
sequences : List [Expression ], condlists : List [List [Expression ]]) -> None :
1547
1549
self .left_expr = left_expr
1548
1550
self .sequences = sequences
@@ -1584,9 +1586,9 @@ class DictionaryComprehension(Expression):
1584
1586
value = None # type: Expression
1585
1587
sequences = None # type: List[Expression]
1586
1588
condlists = None # type: List[List[Expression]]
1587
- indices = None # type: List[Expression ]
1589
+ indices = None # type: List[Lvalue ]
1588
1590
1589
- def __init__ (self , key : Expression , value : Expression , indices : List [Expression ],
1591
+ def __init__ (self , key : Expression , value : Expression , indices : List [Lvalue ],
1590
1592
sequences : List [Expression ], condlists : List [List [Expression ]]) -> None :
1591
1593
self .key = key
1592
1594
self .value = value
@@ -2026,7 +2028,7 @@ def __str__(self) -> str:
2026
2028
('Names' , sorted (self .names .keys ()))],
2027
2029
'TypeInfo' )
2028
2030
2029
- def serialize (self ) -> Union [ str , JsonDict ] :
2031
+ def serialize (self ) -> JsonDict :
2030
2032
# NOTE: This is where all ClassDefs originate, so there shouldn't be duplicates.
2031
2033
data = {'.class' : 'TypeInfo' ,
2032
2034
'module_name' : self .module_name ,
0 commit comments