[pylint] Show verbatim constant in magic-value-comparison (PLR2004)#9694
Merged
charliermarsh merged 1 commit intoastral-sh:mainfrom Jan 30, 2024
Merged
[pylint] Show verbatim constant in magic-value-comparison (PLR2004)#9694charliermarsh merged 1 commit intoastral-sh:mainfrom
pylint] Show verbatim constant in magic-value-comparison (PLR2004)#9694charliermarsh merged 1 commit intoastral-sh:mainfrom
Conversation
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PLR2004 | 6014 | 3007 | 3007 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+3007 -3007 violations, +0 -0 fixes in 4 projects; 39 projects unchanged)
apache/airflow (+1897 -1897 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --preview --select ALL
- airflow/api_connexion/security.py:50:36: PLR2004 Magic value used in comparison, consider replacing 200 with a constant variable + airflow/api_connexion/security.py:50:36: PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable - airflow/api_internal/internal_api_call.py:104:36: PLR2004 Magic value used in comparison, consider replacing 200 with a constant variable + airflow/api_internal/internal_api_call.py:104:36: PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable - airflow/cli/commands/kubernetes_command.py:83:30: PLR2004 Magic value used in comparison, consider replacing 5 with a constant variable + airflow/cli/commands/kubernetes_command.py:83:30: PLR2004 Magic value used in comparison, consider replacing `5` with a constant variable - airflow/configuration.py:2196:37: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + airflow/configuration.py:2196:37: PLR2004 Magic value used in comparison, consider replacing `2` with a constant variable - airflow/example_dags/example_kubernetes_executor.py:135:28: PLR2004 Magic value used in comparison, consider replacing 4 with a constant variable + airflow/example_dags/example_kubernetes_executor.py:135:28: PLR2004 Magic value used in comparison, consider replacing `4` with a constant variable - airflow/executors/base_executor.py:449:27: PLR2004 Magic value used in comparison, consider replacing 3 with a constant variable + airflow/executors/base_executor.py:449:27: PLR2004 Magic value used in comparison, consider replacing `3` with a constant variable - airflow/jobs/triggerer_job_runner.py:481:49: PLR2004 Magic value used in comparison, consider replacing 60 with a constant variable + airflow/jobs/triggerer_job_runner.py:481:49: PLR2004 Magic value used in comparison, consider replacing `60` with a constant variable - airflow/jobs/triggerer_job_runner.py:577:31: PLR2004 Magic value used in comparison, consider replacing 0.2 with a constant variable + airflow/jobs/triggerer_job_runner.py:577:31: PLR2004 Magic value used in comparison, consider replacing `0.2` with a constant variable - airflow/kubernetes/pre_7_4_0_compatibility/pod_generator.py:401:26: PLR2004 Magic value used in comparison, consider replacing 253 with a constant variable + airflow/kubernetes/pre_7_4_0_compatibility/pod_generator.py:401:26: PLR2004 Magic value used in comparison, consider replacing `253` with a constant variable - airflow/models/connection.py:230:35: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + airflow/models/connection.py:230:35: PLR2004 Magic value used in comparison, consider replacing `2` with a constant variable - airflow/models/connection.py:232:54: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + airflow/models/connection.py:232:54: PLR2004 Magic value used in comparison, consider replacing `2` with a constant variable - airflow/providers/airbyte/hooks/airbyte.py:189:35: PLR2004 Magic value used in comparison, consider replacing 200 with a constant variable + airflow/providers/airbyte/hooks/airbyte.py:189:35: PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable - airflow/providers/amazon/aws/hooks/base_aws.py:261:40: PLR2004 Magic value used in comparison, consider replacing 200 with a constant variable + airflow/providers/amazon/aws/hooks/base_aws.py:261:40: PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable - airflow/providers/amazon/aws/hooks/base_aws.py:870:50: PLR2004 Magic value used in comparison, consider replacing 200 with a constant variable + airflow/providers/amazon/aws/hooks/base_aws.py:870:50: PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable - airflow/providers/amazon/aws/hooks/chime.py:88:27: PLR2004 Magic value used in comparison, consider replacing 4096 with a constant variable + airflow/providers/amazon/aws/hooks/chime.py:88:27: PLR2004 Magic value used in comparison, consider replacing `4096` with a constant variable - airflow/providers/amazon/aws/hooks/emr.py:168:62: PLR2004 Magic value used in comparison, consider replacing 200 with a constant variable ... 3763 additional changes omitted for project
aws/aws-sam-cli (+13 -13 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --preview
- tests/integration/testdata/remote_invoke/lambda-fns/main.py:37:26: PLR2004 Magic value used in comparison, consider replacing 100 with a constant variable + tests/integration/testdata/remote_invoke/lambda-fns/main.py:37:26: PLR2004 Magic value used in comparison, consider replacing `100` with a constant variable - tests/smoke/download_sar_templates.py:19:47: PLR2004 Magic value used in comparison, consider replacing 10 with a constant variable + tests/smoke/download_sar_templates.py:19:47: PLR2004 Magic value used in comparison, consider replacing `10` with a constant variable - tests/smoke/download_sar_templates.py:24:50: PLR2004 Magic value used in comparison, consider replacing 10 with a constant variable + tests/smoke/download_sar_templates.py:24:50: PLR2004 Magic value used in comparison, consider replacing `10` with a constant variable - tests/unit/lib/bootstrap/companion_stack/test_companion_stack_manager.py:127:39: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + tests/unit/lib/bootstrap/companion_stack/test_companion_stack_manager.py:127:39: PLR2004 Magic value used in comparison, consider replacing `2` with a constant variable - tests/unit/lib/package/test_artifact_exporter.py:1849:70: PLR2004 Magic value used in comparison, consider replacing 32841 with a constant variable + tests/unit/lib/package/test_artifact_exporter.py:1849:70: PLR2004 Magic value used in comparison, consider replacing `0o100111` with a constant variable ... 16 additional changes omitted for project
bokeh/bokeh (+930 -930 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --preview --select ALL
- examples/basic/data/filter_boolean.py:7:26: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + examples/basic/data/filter_boolean.py:7:26: PLR2004 Magic value used in comparison, consider replacing `2` with a constant variable - examples/basic/data/linked_brushing_subsets.py:13:50: PLR2004 Magic value used in comparison, consider replacing 250 with a constant variable + examples/basic/data/linked_brushing_subsets.py:13:50: PLR2004 Magic value used in comparison, consider replacing `250` with a constant variable - examples/basic/data/linked_brushing_subsets.py:13:61: PLR2004 Magic value used in comparison, consider replacing 100 with a constant variable + examples/basic/data/linked_brushing_subsets.py:13:61: PLR2004 Magic value used in comparison, consider replacing `100` with a constant variable - examples/basic/scatters/elements.py:21:50: PLR2004 Magic value used in comparison, consider replacing 82 with a constant variable + examples/basic/scatters/elements.py:21:50: PLR2004 Magic value used in comparison, consider replacing `82` with a constant variable - examples/interaction/tools/hover_tooltips_image.py:7:36: PLR2004 Magic value used in comparison, consider replacing 0.5 with a constant variable + examples/interaction/tools/hover_tooltips_image.py:7:36: PLR2004 Magic value used in comparison, consider replacing `0.5` with a constant variable - examples/models/trail.py:44:46: PLR2004 Magic value used in comparison, consider replacing 4 with a constant variable + examples/models/trail.py:44:46: PLR2004 Magic value used in comparison, consider replacing `4` with a constant variable - examples/models/trail.py:45:31: PLR2004 Magic value used in comparison, consider replacing 4 with a constant variable + examples/models/trail.py:45:31: PLR2004 Magic value used in comparison, consider replacing `4` with a constant variable - examples/models/trail.py:45:46: PLR2004 Magic value used in comparison, consider replacing 6 with a constant variable ... 1845 additional changes omitted for project
zulip/zulip (+167 -167 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --preview --select ALL
- analytics/lib/counts.py:466:23: PLR2004 Magic value used in comparison, consider replacing 60 with a constant variable + analytics/lib/counts.py:466:23: PLR2004 Magic value used in comparison, consider replacing `60` with a constant variable - analytics/lib/fixtures.py:58:17: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + analytics/lib/fixtures.py:58:17: PLR2004 Magic value used in comparison, consider replacing `2` with a constant variable - analytics/tests/test_activity_views.py:303:20: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + analytics/tests/test_activity_views.py:303:20: PLR2004 Magic value used in comparison, consider replacing `2` with a constant variable - analytics/views/installation_activity.py:241:48: PLR2004 Magic value used in comparison, consider replacing 5 with a constant variable + analytics/views/installation_activity.py:241:48: PLR2004 Magic value used in comparison, consider replacing `5` with a constant variable - analytics/views/support.py:219:25: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + analytics/views/support.py:219:25: PLR2004 Magic value used in comparison, consider replacing `2` with a constant variable ... 324 additional changes omitted for project
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PLR2004 | 6014 | 3007 | 3007 | 0 | 0 |
charliermarsh
approved these changes
Jan 30, 2024
Member
charliermarsh
left a comment
There was a problem hiding this comment.
Thanks! Makes sense to me.
pylint] - improve PLR2004 (magic-value-comparison) to show the constant itself instead of the valuepylint] Improve magic-value-comparison (PLR2004) to show verbatim constant
pylint] Improve magic-value-comparison (PLR2004) to show verbatim constantpylint] Show verbatim constant in magic-value-comparison (PLR2004)
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
Tweaks PLR2004 to show the literal source text, rather than the constant value.
I noticed this when I had a hexadecimal constant, and the linter turned it into base-10.
Now, if you have
0x300, it will show0x300instead of768.Also, added backticks around the constant in the output message.
Test Plan
cargo test