@@ -872,9 +872,9 @@ def accept(self, visitor: StatementVisitor[T]) -> T:
872872class WhileStmt (Statement ):
873873 expr = None # type: Expression
874874 body = None # type: Block
875- else_body = None # type: Block
875+ else_body = None # type: Optional[ Block]
876876
877- def __init__ (self , expr : Expression , body : Block , else_body : Block ) -> None :
877+ def __init__ (self , expr : Expression , body : Block , else_body : Optional [ Block ] ) -> None :
878878 self .expr = expr
879879 self .body = body
880880 self .else_body = else_body
@@ -891,11 +891,11 @@ class ForStmt(Statement):
891891 # Expression to iterate
892892 expr = None # type: Expression
893893 body = None # type: Block
894- else_body = None # type: Block
894+ else_body = None # type: Optional[ Block]
895895 is_async = False # True if `async for ...` (PEP 492, Python 3.5)
896896
897897 def __init__ (self , index : Lvalue , expr : Expression , body : Block ,
898- else_body : Block , index_type : 'mypy.types.Type' = None ) -> None :
898+ else_body : Optional [ Block ] , index_type : 'mypy.types.Type' = None ) -> None :
899899 self .index = index
900900 self .index_type = index_type
901901 self .expr = expr
@@ -956,10 +956,10 @@ def accept(self, visitor: StatementVisitor[T]) -> T:
956956class IfStmt (Statement ):
957957 expr = None # type: List[Expression]
958958 body = None # type: List[Block]
959- else_body = None # type: Block
959+ else_body = None # type: Optional[ Block]
960960
961961 def __init__ (self , expr : List [Expression ], body : List [Block ],
962- else_body : Block ) -> None :
962+ else_body : Optional [ Block ] ) -> None :
963963 self .expr = expr
964964 self .body = body
965965 self .else_body = else_body
@@ -969,10 +969,11 @@ def accept(self, visitor: StatementVisitor[T]) -> T:
969969
970970
971971class RaiseStmt (Statement ):
972- expr = None # type: Expression
973- from_expr = None # type: Expression
972+ # Plain 'raise' is a valid statement.
973+ expr = None # type: Optional[Expression]
974+ from_expr = None # type: Optional[Expression]
974975
975- def __init__ (self , expr : Expression , from_expr : Expression = None ) -> None :
976+ def __init__ (self , expr : Optional [ Expression ] , from_expr : Optional [ Expression ] ) -> None :
976977 self .expr = expr
977978 self .from_expr = from_expr
978979
@@ -982,15 +983,17 @@ def accept(self, visitor: StatementVisitor[T]) -> T:
982983
983984class TryStmt (Statement ):
984985 body = None # type: Block # Try body
985- types = None # type: List[Expression] # Except type expressions
986- vars = None # type: List[NameExpr] # Except variable names
986+ # Plain 'except:' also possible
987+ types = None # type: List[Optional[Expression]] # Except type expressions
988+ vars = None # type: List[Optional[NameExpr]] # Except variable names
987989 handlers = None # type: List[Block] # Except bodies
988- else_body = None # type: Block
989- finally_body = None # type: Block
990+ else_body = None # type: Optional[ Block]
991+ finally_body = None # type: Optional[ Block]
990992
991- def __init__ (self , body : Block , vars : List ['NameExpr' ], types : List [Expression ],
992- handlers : List [Block ], else_body : Block ,
993- finally_body : Block ) -> None :
993+ def __init__ (self , body : Block , vars : List [Optional ['NameExpr' ]],
994+ types : List [Optional [Expression ]],
995+ handlers : List [Block ], else_body : Optional [Block ],
996+ finally_body : Optional [Block ]) -> None :
994997 self .body = body
995998 self .vars = vars
996999 self .types = types
@@ -1004,13 +1007,13 @@ def accept(self, visitor: StatementVisitor[T]) -> T:
10041007
10051008class WithStmt (Statement ):
10061009 expr = None # type: List[Expression]
1007- target = None # type: List[Lvalue]
1010+ target = None # type: List[Optional[ Lvalue] ]
10081011 # Type given by type comments for target, can be None
10091012 target_type = None # type: mypy.types.Type
10101013 body = None # type: Block
10111014 is_async = False # True if `async with ...` (PEP 492, Python 3.5)
10121015
1013- def __init__ (self , expr : List [Expression ], target : List [Lvalue ],
1016+ def __init__ (self , expr : List [Expression ], target : List [Optional [ Lvalue ] ],
10141017 body : Block , target_type : 'mypy.types.Type' = None ) -> None :
10151018 self .expr = expr
10161019 self .target = target
@@ -1351,7 +1354,7 @@ class UnaryExpr(Expression):
13511354 op = ''
13521355 expr = None # type: Expression
13531356 # Inferred operator method type
1354- method_type = None # type: mypy.types.Type
1357+ method_type = None # type: Optional[ mypy.types.Type]
13551358
13561359 def __init__ (self , op : str , expr : Expression ) -> None :
13571360 self .op = op
@@ -1433,7 +1436,7 @@ class OpExpr(Expression):
14331436 left = None # type: Expression
14341437 right = None # type: Expression
14351438 # Inferred type for the operator method type (when relevant).
1436- method_type = None # type: mypy.types.Type
1439+ method_type = None # type: Optional[ mypy.types.Type]
14371440
14381441 def __init__ (self , op : str , left : Expression , right : Expression ) -> None :
14391442 self .op = op
@@ -1452,7 +1455,7 @@ class ComparisonExpr(Expression):
14521455 operators = None # type: List[str]
14531456 operands = None # type: List[Expression]
14541457 # Inferred type for the operator methods (when relevant; None for 'is').
1455- method_types = None # type: List[mypy.types.Type]
1458+ method_types = None # type: List[Optional[ mypy.types.Type] ]
14561459
14571460 def __init__ (self , operators : List [str ], operands : List [Expression ]) -> None :
14581461 self .operators = operators
0 commit comments