codegen
codegen copied to clipboard
Operator precedence is not being handled
Operator precedence is not being properly handled. A couple of examples:
>>> to_ast = lambda x:ast.parse(x, mode='eval')
>>> codegen.to_source(to_ast( '(1+2)*3' ))
'1 + 2 * 3'
1+2*3 = 7. (1+2)*3 = 9
>>> codegen.to_source(to_ast( '( "%s " % (sep,) ).join(foo)' ))
"'%s ' % (sep,).join(foo)"
This is evaluated as '%s ' % ((sep,).join(foo)) because . is higher precedence than %
The version of this at https://github.com/berkerpeksag/astor handles this properly.