Commit bbff8ada authored by Tom Niget's avatar Tom Niget

Fix literal code emission for containers when empty

parent 3b0e9216
......@@ -183,14 +183,22 @@ class ExpressionVisitor(NodeVisitor):
yield node.attr
def visit_List(self, node: ast.List) -> Iterable[str]:
if node.elts:
yield "PyList{"
yield from join(", ", map(self.reset().visit, node.elts))
yield "}"
else:
yield from self.visit(node.type)
yield "{}"
def visit_Set(self, node: ast.Set) -> Iterable[str]:
if node.elts:
yield "PySet{"
yield from join(", ", map(self.reset().visit, node.elts))
yield "}"
else:
yield from self.visit(node.type)
yield "{}"
def visit_Dict(self, node: ast.Dict) -> Iterable[str]:
def visit_item(key, value):
......@@ -200,9 +208,13 @@ class ExpressionVisitor(NodeVisitor):
yield from self.reset().visit(value)
yield "}"
if node.keys:
yield "PyDict{"
yield from join(", ", map(visit_item, node.keys, node.values))
yield "}"
else:
yield from self.visit(node.type)
yield "{}"
def visit_Subscript(self, node: ast.Subscript) -> Iterable[str]:
yield from self.prec("[]").visit(node.value)
......
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