-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Autofix for W1510 #323
Conversation
|
||
proc = subprocess.run(["ls"]) | ||
""", | ||
"""proc = subprocess.run(["ls"], check=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens for multiline?
proc = subprocess.run(
["ls"],
cwd=".",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Might take me a little bit to figure this one out Not sure I have done a multiline fix before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karthiknadig , man am i stuck on this.... looks like this won't fit into the regex pattern easily.
I feel like there should be a simpler way for us to add a new parameter to a function call like subprocess.run, any examples of doing something like this anywhere else that we can go off of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brettcannon Any recommendation on how we can do this?
Other than actually using a parser to find the right spot, I don't see a way to do this correctly. I honestly think that these change recommendations could be generated from pylint itself. Then all we would have to do is surface them via code actions.
/cc @DanielNoord
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a way to autofix code directly in pylint right now but we have an open issue for this: pylint-dev/pylint#7438. The fix is certainly going to be easier in the context of pylint where we sometime already display the suggestion in the message... vs by regex here :) We also have a lot on our plate so any help would be greatly appreciated and reviewed promptly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a keyword argument, you could find the closing )
and then prepend to it, but that's assuming you aren't dealing with any nested parentheses. Otherwise you're wading into using the ast
module to parse the code, update the AST, and then regenerate the string representation (which even using ast.unparse()
doesn't not guarantee an exact result).
Basically you're playing with 🔥 on this one.
Closing this since we don't have a good solution for : #323 (comment) |
subprocess-run-check / W1510
For #43