I'd like to recreate this expression with Python AST:
1 == 2; 1 >= 2
And I can achieve this with the following AST structure:
Module(
body=[
Expr(value=Compare(left=Num(n=1), ops=[Eq()], comparators=[Num(n=2)])),
Expr(value=Compare(left=Num(n=1), ops=[GtE()], comparators=[Num(n=2)]))
]
)
But the above AST structure is identical for 2 expression in a single line and 2 expressions, each in a separate line.
I know that I can manually calculate and modify the nodes' col_offset and lineno attributes to make it a signle line expression, but is there an easier way?
ast.parseit, and if you don't have source code, you don't really have lines, either, so you might as well fill in dummy values for all thecol_offsets andlinenos. - user2357112 supports Monica