-
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
[ruff
] Detect more strict-integer expressions (RUF046
)
#14833
base: main
Are you sure you want to change the base?
Conversation
ruff
] Detect more strict-integer expressions (RUF046
)
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF046 | 2 | 2 | 0 | 0 | 0 |
Hmm, I can't change the base branch if the target is from a fork. I'll wait reviewing this PR until the target is merged. |
Would you mind writing a short summary of what you're changing in the PR description? It's hard to review code if the change is unclear. Did you review through the ecosystem changes? It's unclear to me why we're no longer flagging |
@MichaReiser These changes are all expected, even if they don't seem correct at first sight. For example: # vvvvvvvvvvvvv Not `int`.
def load_data_from_files(..., exclusion_percentage: Optional[int] = None) -> ...:
...
# vvvvvvvvvvvvvvvvvvvvvvvvvvvv This is classified as "Maybe" rather than "Likely".
idx = int(round(exclusion_percentage / 100.0 * len(story_steps)))
# \______This thus might also not be `int`______/ However, I also agree that this is suboptimal. |
82ebdef
to
e4185d2
Compare
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.
Would you mind updating your PR with a short summary outlining the change? It's otherwise very difficult to review the PR without even knowing what the intended behavior is.
The goal of this PR is to correctly detect To give an example, There are, however, limitations. |
Thanks for the extra explanation. That's helpful. I don't think the pattern is common enough to justify the increase in complexity. Unless we move some of the logic into |
@MichaReiser On the other hand, it is:
That's without function calls, variables and such. There's also |
I'm not suggesting that we should not improve the rule at all, but I'm wary of making rules unnecessarily complex by implementing too much ad hoc type inference. It results in inconsistent behavior between rules and makes Ruff harder to maintain. Can we focus on the most important cases you outlined above: single numbers, mathematical expressions, and a few known function calls? It also makes me wonder if we could move some or most of the logic into |
But I'm already focused on such expressions. All three kinds you mention, yes.
|
Summary
Part 2 of the big change introduced in #14828 and the follow-up to #14832.
Test Plan
cargo nextest run
andcargo insta test
.