-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ruff] New rule float-comparison (RUF067)
#20585
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
|
We need more tests and cases where the rule can give FP and so on |
|
Also, I randomly picked CODE for this rule |
|
I haven't reviewed, but if there's not a corresponding E723 rule in pycodestyle, I would default to making this a ruff rule. We have a PR in progress for RUF066, so RUF067 would be the next free code. |
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| RUF067 | 1085 | 1085 | 0 | 0 | 0 |
pycodestyle] New rule float-comparison (E723)ruff] New rule float-comparison (RUF067)
This breaks the behavior of code and results in: |
|
What should we do in such a case? Should we somehow mark this fact in the documentation or what should we do, because we will not be able to check in general that such calls will not lead to some code breakages |
|
The rule detects potentially problematic float comparisons correctly, but we should not suggest replacing only |
|
Would it help with the false positives, and maybe with the numpy cases, to apply the rule only in boolean contexts? I think we have other rules that apply only to expressions used as ruff/crates/ruff_python_semantic/src/model.rs Line 1974 in 5f136c2
This rule is going to require type inference to get exactly right anyway, so this might be a good way to be more conservative in the meantime. I also only gave the implementation a quick skim and could have overlooked this, but does this rule apply to comparisons like |
Yes, this only applies to |

Summary
Part of #14220
Test Plan
cargo nextest run ruf067