Skip to content

Commit

Permalink
modify ast for old syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Feb 17, 2024
1 parent 9d0df92 commit 3e661a1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions vyper/ast/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,25 @@ def visit_Expr(self, node):

return node

def visit_Call(self, node):
"""
Convert structs declared as `Dict` node for vyper < 0.4.0 to kwargs.
"""
if len(node.args) == 1 and isinstance(node.args[0], python_ast.Dict):
dict_ = node.args[0]
kw_list = []

for key, value in zip(dict_.keys, dict_.values):
replacement_kw_node = python_ast.keyword(key.id, value)
kw_list.append(replacement_kw_node)

node.args = []
node.keywords = kw_list

self.generic_visit(node)

return node

def visit_Constant(self, node):
"""
Handle `Constant` when using Python >=3.8
Expand Down

0 comments on commit 3e661a1

Please sign in to comment.