Commit 43829e2b authored by Tom Niget's avatar Tom Niget

Allow empty AnnAssigns (var decls without values)

parent 68b42e9e
......@@ -140,9 +140,12 @@ class BlockVisitor(NodeVisitor):
yield ";"
def visit_AnnAssign(self, node: ast.AnnAssign) -> Iterable[str]:
if node.value is None:
raise NotImplementedError(node, "empty value")
yield from self.visit_lvalue(node.target)
# if node.value is None:
# raise NotImplementedError(node, "empty value")
yield from self.visit_lvalue(node.target, node.is_declare)
if node.value:
yield " = "
yield from self.expr().visit(node.value)
yield ";"
......@@ -56,6 +56,19 @@ class ScoperBlockVisitor(ScoperVisitor):
ty = self.get_type(node.value)
try:
node.is_declare = self.visit_assign_target(target, ty)
except IncompatibleTypesError as e:
raise IncompatibleTypesError(f"`{ast.unparse(node)}: {e}") from e
def visit_AnnAssign(self, node: ast.AnnAssign):
if node.value is not None:
raise NotImplementedError(node)
if node.simple != 1:
raise NotImplementedError(node)
if not isinstance(node.target, ast.Name):
raise NotImplementedError(node)
ty = self.visit_annotation(node.annotation)
try:
node.is_declare = self.visit_assign_target(node.target, ty)
except IncompatibleTypesError as e:
raise IncompatibleTypesError(f"`{ast.unparse(node)}: {e}")
......
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