-
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
[pylint
] Implement if-stmt-min-max
(PLR1730
, PLR1731
)
#10002
[pylint
] Implement if-stmt-min-max
(PLR1730
, PLR1731
)
#10002
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLR6301 | 136 | 68 | 68 | 0 | 0 |
PLR1730 | 7 | 7 | 0 | 0 | 0 |
PLR6201 | 4 | 2 | 2 | 0 | 0 |
Hi @charliermarsh, some questions regarding this PR:
|
Another related rule: #1348 implemented as https://docs.astral.sh/ruff/rules/if-expr-min-max/ |
@sbrugman While they look indeed similar, the implementation is quite different: FURB136 is for if expressions (in ruff it is ExprIfExp which is an Expr enum), whereas PLR1730 operates on if statements (in ruff it is StmtIf which is a Stmt enum). |
I linked it as reference for the first point: here it is implemented as a single rule. Consistency with the upstream (mapping existing rules) takes precedence over internal consistency (merging rules that are minimally different) I suppose, so just for reference. Nice work! |
0137351
to
85f4a58
Compare
@sbrugman Thanks for clarifying, I misunderstood your original comment. I added now a commit which merges the 2 rules - I personally also prefer this over the duplication. @charliermarsh to decide if this is acceptable - i.e. dropping PLR1731 and just using PLR1730 for both min and max. |
Sorry for the confusion, but I intended to say that the linked rule merged them at one, but since that pylint treats them as two for now the project prefers to match pylint (i.e. two rules). Anyway, indeed let the team decide on that |
85f4a58
to
320aea4
Compare
@sbrugman From the linked reference I found out that there is ComparableExpr - code looks a lot cleaner now. So thanks a lot for taking a look! |
The rule itself fits into ruff. It is similar to if-expr-min-max but we have other rules that capture the same problem but differ in the syntax. I think we should align the name with One thing that needs to be decided if this should be a single rule or if it's better to have two rules (to match py lint) |
I'm comfortable with a single rule here. Just seems unlikely that anyone would enable one but not the other, and it better aligns with |
pylint
] Implement if-stmt-min-max
(PLR1730
, PLR1731
)
…-sh#10002) Add rule [consider-using-min-builtin (R1730)](https://pylint.readthedocs.io/en/latest/user_guide/messages/refactor/consider-using-min-builtin.html) and [consider-using-max-builtin (R1731)](https://pylint.readthedocs.io/en/latest/user_guide/messages/refactor/consider-using-max-builtin.html) See astral-sh#970 for rules Test Plan: `cargo test`
Add rule consider-using-min-builtin (R1730) and consider-using-max-builtin (R1731)
See #970 for rules
Test Plan:
cargo test