-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[refurb
] Fix FURB129
autofix generating invalid syntax
#18235
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
Conversation
let unparenthesized_item_range = parenthesized_range.add_start(1.into()).sub_end(1.into()); | ||
let item_str = checker.locator().slice(unparenthesized_item_range); | ||
Edit::range_replacement(item_str.to_string(), expr_call.range()) |
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.
Is there a better way to unpack the parenthesized expression here? I looked but didn't find any.
When the expression has multiple parenthesis like in:
with open("furb129.py") as f:
for line in (((f))).readlines():
pass
the fix will generate this for line in ((f)):
, would that be the correct behavior or should it be just f
?
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.
Is it necessary to remove any parentheses? Removing them when fixing for line in(f).readlines()
would produce a syntax error, similar to #17683.
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.
Is it necessary to remove any parentheses?
Not really, I guess.
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.
Is it necessary to remove any parentheses? Removing them when fixing
for line in(f).readlines()
would produce a syntax error, similar to #17683.
But for line in f.readlines()
is not incorrect syntax. Syntax error itself is for line in(f)
block: in
is not a function and whitespace should not be removed
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.
But
for line in f.readlines()
is not incorrect syntax. Syntax error itself isfor line in(f)
block:in
is not a function and whitespace should not be removed
for line in(f)
is not a syntax error, in
is lexed as a keyword and not as an identifier, so in(f)
is not a function call.
|
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.
Looks good to me, thanks!
Summary
Fixes #18231
Test Plan
Snapshot tests