-
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
PLR2004
: Accept 0.0 and 1.0 as common magic values
#9964
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLR2004 | 35 | 0 | 35 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+0 -35 violations, +0 -0 fixes in 2 projects; 41 projects unchanged)
apache/airflow (+0 -6 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
- tests/core/test_configuration.py:229:16: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/jobs/test_scheduler_job.py:4941:24: PLR2004 Magic value used in comparison, consider replacing `0.0` with a constant variable - tests/jobs/test_scheduler_job.py:4966:24: PLR2004 Magic value used in comparison, consider replacing `0.0` with a constant variable - tests/providers/google/cloud/transfers/test_cassandra_to_gcs.py:87:41: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/utils/test_sqlalchemy.py:89:62: PLR2004 Magic value used in comparison, consider replacing `0.0` with a constant variable - tests/utils/test_sqlalchemy.py:90:58: PLR2004 Magic value used in comparison, consider replacing `0.0` with a constant variable
bokeh/bokeh (+0 -29 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
- src/bokeh/colors/color.py:321:22: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - src/bokeh/colors/color.py:337:21: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - src/bokeh/colors/color.py:460:22: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - src/bokeh/core/property/numeric.py:280:12: PLR2004 Magic value used in comparison, consider replacing `0.0` with a constant variable - src/bokeh/core/property/numeric.py:280:28: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - src/bokeh/palettes.py:1621:17: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - src/bokeh/plotting/contour.py:414:53: PLR2004 Magic value used in comparison, consider replacing `0.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:107:23: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:156:24: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:164:24: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:194:24: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:211:23: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:283:24: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:333:24: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:341:24: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:362:63: PLR2004 Magic value used in comparison, consider replacing `0.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:365:63: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_color__colors.py:85:24: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/colors/test_named.py:189:19: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/models/_util_models.py:121:30: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/models/_util_models.py:130:30: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/models/test_annotations.py:155:37: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/models/test_annotations.py:497:32: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/models/test_annotations.py:498:38: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/models/test_annotations.py:547:28: PLR2004 Magic value used in comparison, consider replacing `-1.` with a constant variable - tests/unit/bokeh/models/test_annotations.py:551:25: PLR2004 Magic value used in comparison, consider replacing `-1.` with a constant variable - tests/unit/bokeh/models/test_glyphs.py:356:34: PLR2004 Magic value used in comparison, consider replacing `1.0` with a constant variable - tests/unit/bokeh/models/test_ranges.py:160:37: PLR2004 Magic value used in comparison, consider replacing `-1.0` with a constant variable - tests/unit/bokeh/models/test_ranges.py:71:33: PLR2004 Magic value used in comparison, consider replacing `-1.0` with a constant variable
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLR2004 | 35 | 0 | 35 | 0 | 0 |
I think this is a good change and arguably a "bug" (or at least an oversight) given that we already allow |
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.
Seems reasonable without preview — looks like a bug.
## Summary Accept 0.0 and 1.0 as common magic values. This is in line with the pylint behaviour, and I think makes sense conceptually. ## Test Plan Test cases were added to `crates/ruff_linter/resources/test/fixtures/pylint/magic_value_comparison.py`
Summary
Accept 0.0 and 1.0 as common magic values. This is in line with the pylint behaviour, and I think makes sense conceptually.
Test Plan
Test cases were added to
crates/ruff_linter/resources/test/fixtures/pylint/magic_value_comparison.py