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