Kaydet (Commit) 363a326e authored tarafından Ryan Gonzalez's avatar Ryan Gonzalez

Add support for variable annotations

üst 49a35d8f
......@@ -11,4 +11,5 @@
0.4.1 -- Added missing SourceGenerator.visit_arguments()
0.5 -- Added support for Python 3.5 infix matrix
multiplication
0.6 -- Added support for Python 3.6 f-strings and async comprehensions.
0.6 -- Added support for Python 3.6 f-strings, async comprehensions, and
variable annotations.
......@@ -247,6 +247,17 @@ class SourceGenerator(ExplicitNodeVisitor):
self.statement(node, node.target, get_op_symbol(node.op, ' %s= '),
node.value)
def visit_AnnAssign(self, node):
set_precedence(node, node.value, node.target)
self.newline(node)
if not node.simple and isinstance(node.target, ast.Name):
self.write('(', node.target, ')')
else:
self.write(node.target)
self.write(': ', node.annotation)
if node.value is not None:
self.write(' = ', node.value)
def visit_ImportFrom(self, node):
self.statement(node, 'from ', node.level * '.',
node.module or '', ' import ')
......
......@@ -17,6 +17,7 @@ op_data = """
GeneratorExp 1
Assign 1
AnnAssign 1
AugAssign 0
Expr 0
Yield 1
......
......@@ -373,5 +373,13 @@ class CodegenTestCase(unittest.TestCase):
"""
self.assertAstSourceEqualIfAtLeastVersion(source, (3, 6))
def test_annassign(self):
source = """
a: int
(b): Tuple[int, str, ...]
c.d[e].f: Any
"""
self.assertAstEqualIfAtLeastVersion(source, (3, 6))
if __name__ == '__main__':
unittest.main()
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