You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for building such a great lib on Python AST! However, writing asserts in rules is pretty tedious, I wonder if it's possible to parse a target python AST, and generate the rules automatically?
Also, another question is, now that the contract is based on a single ast.Node, is it possible to do a partial replacement with multiple statements (spans multiple ast.Nodes)?
For example, how do I write the rule to replace all matches of the following 2 statements:
@void-main I am just a beginner using this package! The way I do these is by iterating the body of say a FunctionDef, find the match, clone and make the changes, then yield Replace(..., ...) - It seems to work. Note that I look for the minimal change, for example if I just want to change say 1 is your example, I make sure that I get to that Constant() and only change it, this way I think it minimizes the MaybeOverlapping
However, writing asserts in rules is pretty tedious, I wonder if it's possible to parse a target python AST, and generate the rules automatically?
One example I can think of is @lmmx's refactory which uses Refactor as a backend and takes the input search form which can be later compiled down to refactor expression. I can't see why this won't be possible as well, as long as some one is interested in writing it down :)
Also, another question is, now that the contract is based on a single ast.Node, is it possible to do a partial replacement with multiple statements (spans multiple ast.Nodes)?
As @MementoRC pointed, indeed it is a use case which is supported but needs a bit more precision to avoid overlaps. This is called Chained or composite actions in our docs, which includes a few more examples. It is still an experimental feature, so would love to hear your feedback as well.
Thanks for building such a great lib on Python AST! However, writing
asserts
in rules is pretty tedious, I wonder if it's possible to parse a target python AST, and generate the rules automatically?Also, another question is, now that the
contract
is based on a singleast.Node
, is it possible to do a partial replacement with multiple statements (spans multiple ast.Nodes)?For example, how do I write the rule to replace all matches of the following 2 statements:
Do I have to do it in a larger scope node (say
ast.FunctionDef
)? Or is it possible to get someUD-Chains
based on the currentast.Node
?The text was updated successfully, but these errors were encountered: