Skip to content

Unparsed code missing parents around BinOp #88

@muirdm

Description

@muirdm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions