Note that for the assignment annotation to appear in the typed AST, you need to run the type inference with Python 3.6+
The typed AST construction works as follows:
In every context, keep track of the function definition and assignment nodes that appear in it.
At the end of the inference, traverse the context hierarchy and add the annotations to the nodes stored in each one.
For function definitions, use the annotation resolver to unparse Z3 types of the arguments and the return into PEP 484 syntax, then add them to the stored AST nodes.
For assignment, check that Python 3.6 runs the inference, and check that it is a simple single assignment (The only assignment supported by the variable annotation syntax), then change the node's class from ast.Assign to ast.AnnAssign, to enable the AST unparser to unparse it into the syntax of the variable annotation.
Either generate a new file for typed source or just print it.
Note that for the assignment annotation to appear in the typed AST, you need to run the type inference with Python 3.6+
The typed AST construction works as follows:
ast.Assign
toast.AnnAssign
, to enable the AST unparser to unparse it into the syntax of the variable annotation.