PLR2004: Accept 0.0 and 1.0 as common magic values#9964
Merged
charliermarsh merged 3 commits intoastral-sh:mainfrom Feb 13, 2024
Merged
PLR2004: Accept 0.0 and 1.0 as common magic values#9964charliermarsh merged 3 commits intoastral-sh:mainfrom
PLR2004: Accept 0.0 and 1.0 as common magic values#9964charliermarsh merged 3 commits intoastral-sh:mainfrom
Conversation
Contributor
|
| 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 |
Member
|
I think this is a good change and arguably a "bug" (or at least an oversight) given that we already allow |
zanieb
approved these changes
Feb 13, 2024
Member
zanieb
left a comment
There was a problem hiding this comment.
Seems reasonable without preview — looks like a bug.
charliermarsh
approved these changes
Feb 13, 2024
nkxxll
pushed a commit
to nkxxll/ruff
that referenced
this pull request
Mar 10, 2024
## 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`
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
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