refactor
refactor copied to clipboard
Unparsed code missing parents around BinOp
With a simplified runner like:
import ast
import refactor
class Replace(refactor.Rule):
def match(self, node):
if type(node) == ast.Call:
return refactor.Replace(
node,
ast.Call(
ast.Attribute(node.args[0], node.func.id),
node.args[1:],
node.keywords,
),
)
return None
if __name__ == "__main__":
refactor.run(rules=[Replace])
Running it against:
foo(1 + 2)
I expect the output:
(1 + 2).foo()
But it produces the invalid:
1 + 2.foo()
The stdlib ast.unparse() seems to do this correctly, so I suspect it is a problem in refactor.
Also note that the issue isn't limited to BinOp.