Commit b7366b68 authored by Zejun Lin's avatar Zejun Lin Committed by QuanluZhang
Browse files

support dict_type in annotation (#720)

fix bug in annotation, code generator cannot deal with dict as left value of assignment expression.
parent cba17a57
...@@ -126,15 +126,23 @@ def make_lambda(call): ...@@ -126,15 +126,23 @@ def make_lambda(call):
return ast.Lambda(args=empty_args, body=call) return ast.Lambda(args=empty_args, body=call)
def test_variable_equal(var1, var2): def test_variable_equal(node1, node2):
"""Test whether two variables are the same.""" """Test whether two variables are the same."""
if type(var1) is not type(var2): if type(node1) is not type(node2):
return False return False
if type(var1) is ast.Name: if isinstance(node1, ast.AST):
return var1.id == var2.id for k, v in vars(node1).items():
if type(var1) is ast.Attribute: if k in ('lineno', 'col_offset', 'ctx'):
return var1.attr == var2.attr and test_variable_equal(var1.value, var2.value) continue
return False if not test_variable_equal(v, getattr(node2, k)):
return False
return True
if isinstance(node1, list):
if len(node1) != len(node2):
return False
return all(test_variable_equal(n1, n2) for n1, n2 in zip(node1, node2))
return node1 == node2
def replace_variable_node(node, annotation): def replace_variable_node(node, annotation):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment