Repository navigation
[ruff] Avoid false positives for overloaded division (RUF069) - #28309
Merged
ntBre merged 1 commit intoSep 17, 2026
Merged
Conversation
IbrahimKhan12
marked this pull request as ready for review
September 4, 2026 10:55
ntBre
reviewed
Sep 4, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thanks! This looks good, just a couple of very small nits.
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| float-equality-comparison | 55 | 4 | 51 | 0 | 0 |
| RUF069 | 2 | 2 | 0 | 0 | 0 |
- Treat division like other binary expressions when detecting floats. - Cover built-in and Decimal division regression cases.
IbrahimKhan12
force-pushed
the
fix-ruf069-overloaded-division
branch
from
September 6, 2026 19:16
21feb44 to
0612898
Compare
Contributor
Author
|
nits addressed! |
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
Fixes #23281.
RUF069currently treats division as a floating-point expression whenever either operand is syntactically numeric. This works for built-in numeric division, but Python allows/to be overloaded. As a result, the rule reports false positives forDecimaland custom numeric classes whose division returns an exact, non-float value.This change removes the division-specific heuristic. Division now follows the same logic as other binary expressions: Ruff reports the comparison only when it can identify a float or complex value in the expression.
Without type inference, Ruff cannot determine whether
value / 2uses built-in integer division or an overloaded operator. This change therefore favors false negatives over false positives when the operand types are unknown. Explicit float and complex values remain detected. Future type inference could recover built-in integer-division cases without reintroducing false positives for overloaded operators.The regression fixture covers direct and reverse
Decimaldivision, marks unknown-type division as accepted, and verifies that a float nested inside division still triggers the rule.Test Plan
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ruff_linter ruf069INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run(9,203 passed, 44 skipped)cargo clippy --workspace --all-targets --all-features -- -D warningscargo dev generate-allprekfor all changed filesDecimalreproduction with the Ruff CLI