Merged
Conversation
This implementation diverges from Refurb's original implementation by
retaining the order of equal values. For example, Refurb suggest that
the following expressions:
highest_score1 = score1 if score1 > score2 else score2
highest_score2 = score1 if score1 >= score2 else score2
should be to rewritten as:
highest_score1 = max(score1, score2)
highest_score2 = max(score1, score2)
whereas this implementation provides more correct alternatives:
highest_score1 = max(score2, score1)
highest_score2 = max(score1, score2)
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| FURB136 | 1 | 1 | 0 | 0 | 0 |
Member
charliermarsh
left a comment
There was a problem hiding this comment.
Nice, thank you, this looks great! I may make some small tweaks to better conform to some of our idioms but shouldn't require any major changes.
| flake8_simplify::rules::twisted_arms_in_ifexpr(checker, expr, test, body, orelse); | ||
| } | ||
| if checker.enabled(Rule::IfExprMinMax) { | ||
| refurb::rules::if_expr_min_max(checker, expr, test, body, orelse); |
Member
There was a problem hiding this comment.
Can you instead pass in the ast::ExprIfExp here? That's what we prefer for new rules. So e.g. on line 1284, you'd change to:
Expr::IfExp(if_exp @ ast::ExprIfExp {
test,
body,
orelse,
range: _,
}) => {
...
}And then here, you'd pass in if_exp instead of the destructured fields. That way, callers can't pass in the "wrong" values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements FURB136 that checks for
ifexpressions that can be replaced withmin()ormax()calls. See issue #1348 for more information.This implementation diverges from Refurb's original implementation by retaining the order of equal values. For example, Refurb suggest that the following expressions:
should be to rewritten as:
whereas this implementation provides more correct alternatives:
Test Plan
Unit test checks all eight possibilities.