Skip to content

Commit 915e9cc

Browse files
author
Ivan Levkivskyi
committed
Backward compatibility for typed_ast (without typeshed)
1 parent 32295da commit 915e9cc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mypy/fastparse.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,18 @@ def visit_Delete(self, n: ast35.Delete) -> Node:
403403
else:
404404
return DelStmt(self.visit(n.targets[0]))
405405

406-
# Assign(expr* targets, expr value, string? type_comment)
406+
# Assign(expr* targets, expr? value, expr? type_comment)
407407
@with_line
408408
def visit_Assign(self, n: ast35.Assign) -> Node:
409409
typ = None
410410
if n.type_comment:
411-
if isinstance(n.type_comment, ast35.Str):
411+
if isinstance(n.type_comment, str): # backward-compatibility typed_ast
412+
typ = parse_type_comment(n.type_comment, n.lineno)
413+
elif isinstance(n.type_comment, ast35.Str):
412414
typ = parse_type_comment(n.type_comment.s, n.lineno)
413415
else:
414416
typ = TypeConverter(line=n.lineno).visit(n.type_comment)
415-
if n.value is None:
417+
if n.value is None: # treat 'x: int' as 'x = None # type: int'
416418
n.value = ast35.NameConstant(value=None)
417419
return AssignmentStmt(self.visit_list(n.targets),
418420
self.visit(n.value),

0 commit comments

Comments
 (0)