-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[flake8-return
] - Add fixes for (RET505
, RET506
, RET507
, RET508
)
#9595
[flake8-return
] - Add fixes for (RET505
, RET506
, RET507
, RET508
)
#9595
Conversation
CodSpeed Performance ReportMerging #9595 will degrade performances by 22.56%Comparing Summary
Benchmarks breakdown
|
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RET505 | 1434 | 0 | 0 | 1434 | 0 |
RET506 | 372 | 0 | 0 | 372 | 0 |
RET508 | 50 | 0 | 0 | 50 | 0 |
RET507 | 28 | 0 | 0 | 28 | 0 |
flake8-return
] - add fix for RET505, RET506, RET507, RET508flake8-return
] - Add fixes for (RET505
, RET506
, RET507
, RET508
)
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.
Thanks, that's a very useful fix.
I looked at the performance regression and it's caused by adjust_indentation
calling into libCST. The regression is fine because it only applies to files with that specific violation. It's not that it introduces a slow down for projects that have no violations.
There's one edge case that the code isn't handling correctly but I don't think it's worth addressing. But feel free to give it a try if you want.
Would you mind adding a few more tests that demonstrate how the rule handles comments? We should then be good to merge this.
elif_else.start() + TextSize::from(2), | ||
))) | ||
} else { | ||
let else_line_range = checker.locator().full_line_range(elif_else.start()); |
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.
I don't expect this to exist in practice but assuming that the else
header ends on the same line as the else
keyword is not always true. For example if you have.
if True:
return
else\
:\
# comment
pass
it then keeps :\\n # comment
where it should not. We could use SimpleTokenizer
to detect this but I don't think it's worth doing.
However, I think it would be good to add a few more tests that demonstrate how the fix deals with comments in different positions.
if True:
return
else:
# comment
pass
if True:
return
else: # comment
pass
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.
I've tweaked it to work with that line continuation that I didn't account for, and the code now keeps all comments after the else's :
😄
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.
Nice!
Summary
add fix for RET505, RET506, RET507, RET508
Test Plan
cargo test