-
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-simplify] Further simplify to binary in preview for if-else-block-instead-of-if-exp (SIM108)
#12796
[flake8-simplify] Further simplify to binary in preview for if-else-block-instead-of-if-exp (SIM108)
#12796
Conversation
The edge cases in question are pretty rare - not sure if there is a better way to organize the code (for performance and readability) to take advantage of that. |
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
SIM108 | 14 | 9 | 5 | 0 | 0 |
Sweet, thanks! |
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.
This looks good to me. I just added a check to ensure there's no effect (like a function call) in the test, since it no longer gets repeated.
In most cases we should suggest a ternary operator, but there are three edge cases where a binary operator is more appropriate.
Given an if-else block of the form
This PR updates the check for SIM108 to the following:
test == body_value
and preview enabled, suggest to replace withtarget_var = test or else_value
test == not body_value
and preview enabled, suggest to replace withtarget_var = body_value and else_value
not test == body_value
and preview enabled, suggest to replace withtarget_var = body_value and else_value
target_var = body_value if test else else_value
Closes #12189.