Skip to content
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] Unnecessary ndigits argument to round() (RUF057) #14828

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

InSyncWithFoo
Copy link
Contributor

Summary

Resolves #14793.

Test Plan

cargo nextest run and cargo insta test.

Copy link
Contributor

github-actions bot commented Dec 7, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+2 -6 violations, +0 -0 fixes in 5 projects; 50 projects unchanged)

RasaHQ/rasa (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- rasa/shared/core/training_data/loading.py:86:15: RUF046 Value being casted is already an integer

apache/superset (+0 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- superset/migrations/versions/2018-07-22_11-59_bebcf3fed1fe_convert_dashboard_v1_positions.py:197:40: RUF046 Value being casted is already an integer
- superset/migrations/versions/2018-07-22_11-59_bebcf3fed1fe_convert_dashboard_v1_positions.py:199:29: RUF046 Value being casted is already an integer

bokeh/bokeh (+0 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- src/bokeh/colors/color.py:338:60: RUF046 Value being casted is already an integer
- src/bokeh/palettes.py:1568:10: RUF046 Value being casted is already an integer
- src/bokeh/palettes.py:1569:10: RUF046 Value being casted is already an integer

milvus-io/pymilvus (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ pymilvus/orm/schema.py:827:53: RUF046 [*] Value being casted is already an integer

rotki/rotki (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ rotkehlchen/tests/utils/ethereum.py:231:15: RUF046 [*] Value being casted is already an integer

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF046 8 2 6 0 0

@MichaReiser
Copy link
Member

MichaReiser commented Dec 7, 2024

Thanks for following up on this!

Would you mind splitting the PR into two if it isn't too much work:

  1. Changes the existing rule
  2. Adding the new rule

Two separate PRs have the advantage that we can list the two changes separately in the changelog. It also makes it easier for me to review your PR

@InSyncWithFoo
Copy link
Contributor Author

InSyncWithFoo commented Dec 7, 2024

@MichaReiser I would prefer not having to do that. RUF057 depends on a RUF046 API (expr_is_strictly_int()), which itself comprises most of the change to RUF046.

@MichaReiser
Copy link
Member

MichaReiser commented Dec 7, 2024

Yeah, that's a bit annoying. However, I just skimmed over the changes, and there's too much going on in this PR, which makes it difficult for me and future readers to understand what it is about. That's why I have to insist that you split the PR. I suggest three PRs:

  1. Scope change of RUF046
    2.. Improving the integer inference of RUF046
  2. Adding the new RUF057

I'd suggest you start with one PR and then submit the next once that is merged. Or you can create stacked PRs, but they can be a bit painful when it comes to rebasing them.

@InSyncWithFoo InSyncWithFoo changed the title [ruff] Detect more strict-integer expressions and move round() logic to new rule (RUF046, RUF057) [ruff] Unnecessary ndigits argument to round() (RUF057) Dec 8, 2024
@InSyncWithFoo InSyncWithFoo changed the title [ruff] Unnecessary ndigits argument to round() (RUF057) [ruff] Unnecessary ndigits argument to round() (RUF057) Dec 8, 2024
@InSyncWithFoo
Copy link
Contributor Author

All done. I don't mind a little bit of rebasing, so stacked PRs it is.

@MichaReiser
Copy link
Member

MichaReiser commented Dec 8, 2024

Thank you.

Hmm. This is not the rule I expected. From our conversation in #14793 I'd expected a rule that detects unnecessary round calls rather than unnecessary ndigits.

E.g. round(5) should be converted to just 5. The same for round(5, None)

MichaReiser pushed a commit that referenced this pull request Dec 9, 2024
## Summary

Part 1 of the big change introduced in #14828. This temporarily causes
all fixes for `round(...)` to be considered unsafe, but they will
eventually be enhanced.

## Test Plan

`cargo nextest run` and `cargo insta test`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RUF046 is doing two things instead of one
2 participants