-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement chained comparison improvements and related checks #7611
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
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 3231501930
💛 - Coveralls |
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.
Thank you for the work @areveny. There's a lot to review but from what I can see after a surface review it's possible that making the gragh check's code independent from the RefactoringChecker might be a good idea, because 1) There's a lot of code and maintenance would benefit from it being separated 2) It's going to be easier if we want to extends usiing-constant-tests
directly where it's at instead of refactoring how the checker work to be able to raise any message anywhere.
"Emitted when items in a boolean condition are all <= or >=" | ||
"This is equivalent to asking if they all equal.", | ||
), | ||
"R1738": ( |
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.
Maybe this should raise the existing message for constant comparison using-constant-test
(https://pylint.pycqa.org/en/latest/user_guide/messages/warning/using-constant-test.html#using-constant-test-w0125). We might need to relax some constraint on what checker can do, I'm not sure a checker can raise messages it does not define right now.
Hi @areveny, just wondering: are the false negatives in the primer result one of the items you were hoping to polish after getting an initial review? |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #7611 +/- ##
==========================================
- Coverage 95.76% 95.46% -0.30%
==========================================
Files 173 176 +3
Lines 18616 18649 +33
==========================================
- Hits 17827 17803 -24
- Misses 789 846 +57
|
Hi.
This PR adds improvements to
chained-comparison
by processing the chain of comparisons into a graph. It's still a bit unpolished but I would like some higher-level feedback on the direction.It adds two new checks:
impossible-comparison
for cases when a comparison would always be false, e.g.a > b and b > a
ora == 5 and a > b and b == 1
.comparison-all-equal
for a special cycle case where every comparison allows equality.a >= b >= c and c >= a
simplifies toa == b == c
.It modifies
chained-comparison
to be more accurate, specifically the casea < b < c and a < c
should be simplified to justa < b < c
. It currently is not.It also prints what simplified comparison is.
Unfortunately, this is at the cost of complexity. The algorithm finds the minimum number of comparisons by finding the longest path through the graph of comparisons repeatedly, recalculating all the path lengths after each path is emitted. (I could not get it working by emitting paths in arbitrary order until all nodes are accounted for because of the case above,
a < b < c and a < c
.) The overhead of doing so should be limited by the reality that most comparisons tend to have just a few statements.Please let me know what you think. I'm open to big suggestions, but want to share my code for feedback and to keep this moving.
Type of Changes
Description
Closes #5814