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

[flake8-builtins] Rename A005 and improve its error message #15348

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jan 8, 2025

Summary

This rule is called builtin-module-shadowing and the error message is:

Module abc is shadowing a Python builtin module

But that's not a good description of the rule. There's only one builtins module in Python, but many modules in the Python standard library. This rule complains if you shadow any Python standard-library module, so a better name is stdlib-module-shadowing, and a better error message would be

Module abc shadows a Python standard-library module

This PR makes that change. We'll need to remember to add a redirect rule to the website, or existing links to the rule's documentation (e.g. in our changelog or blogposts) will break.

Test Plan

cargo test -p ruff_linter --lib

@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label Jan 8, 2025
@AlexWaygood AlexWaygood mentioned this pull request Jan 8, 2025
2 tasks
@AlexWaygood AlexWaygood force-pushed the alex/flake8-builtins-message branch from 7170360 to 6057f8a Compare January 8, 2025 12:33
@MichaReiser
Copy link
Member

so a better name is builtin-module-shadowing, and a better error message would be

So the name is already perfect? ;)

@AlexWaygood
Copy link
Member Author

so a better name is builtin-module-shadowing, and a better error message would be

So the name is already perfect? ;)

Oops. Edited my PR description 😇

@AlexWaygood AlexWaygood enabled auto-merge (squash) January 8, 2025 12:36
@AlexWaygood AlexWaygood merged commit 9a27b37 into main Jan 8, 2025
20 checks passed
@AlexWaygood AlexWaygood deleted the alex/flake8-builtins-message branch January 8, 2025 12:38
Copy link
Contributor

github-actions bot commented Jan 8, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+81 -81 violations, +0 -0 fixes in 8 projects; 47 projects unchanged)

Snowflake-Labs/snowcli (+7 -7 violations, +0 -0 fixes)

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

- src/snowflake/cli/_plugins/cortex/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ src/snowflake/cli/_plugins/cortex/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- src/snowflake/cli/_plugins/notebook/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ src/snowflake/cli/_plugins/notebook/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- src/snowflake/cli/api/console/abc.py:1:1: A005 Module `abc` is shadowing a Python builtin module
+ src/snowflake/cli/api/console/abc.py:1:1: A005 Module `abc` shadows a Python standard-library module
- src/snowflake/cli/api/console/enum.py:1:1: A005 Module `enum` is shadowing a Python builtin module
+ src/snowflake/cli/api/console/enum.py:1:1: A005 Module `enum` shadows a Python standard-library module
- src/snowflake/cli/api/errno.py:1:1: A005 Module `errno` is shadowing a Python builtin module
+ src/snowflake/cli/api/errno.py:1:1: A005 Module `errno` shadows a Python standard-library module
... 4 additional changes omitted for project

apache/airflow (+23 -23 violations, +0 -0 fixes)

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

- airflow/api_connexion/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ airflow/api_connexion/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- airflow/api_fastapi/common/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ airflow/api_fastapi/common/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- airflow/api_fastapi/execution_api/datamodels/token.py:1:1: A005 Module `token` is shadowing a Python builtin module
+ airflow/api_fastapi/execution_api/datamodels/token.py:1:1: A005 Module `token` shadows a Python standard-library module
- airflow/io/utils/stat.py:1:1: A005 Module `stat` is shadowing a Python builtin module
+ airflow/io/utils/stat.py:1:1: A005 Module `stat` shadows a Python standard-library module
- airflow/models/operator.py:1:1: A005 Module `operator` is shadowing a Python builtin module
+ airflow/models/operator.py:1:1: A005 Module `operator` shadows a Python standard-library module
- airflow/operators/email.py:1:1: A005 Module `email` is shadowing a Python builtin module
+ airflow/operators/email.py:1:1: A005 Module `email` shadows a Python standard-library module
- airflow/serialization/serializers/datetime.py:1:1: A005 Module `datetime` is shadowing a Python builtin module
+ airflow/serialization/serializers/datetime.py:1:1: A005 Module `datetime` shadows a Python standard-library module
... 32 additional changes omitted for project

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

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

- superset/advanced_data_type/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ superset/advanced_data_type/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- superset/commands/dashboard/copy.py:1:1: A005 Module `copy` is shadowing a Python builtin module
+ superset/commands/dashboard/copy.py:1:1: A005 Module `copy` shadows a Python standard-library module
- superset/dashboards/permalink/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ superset/dashboards/permalink/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- superset/databases/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ superset/databases/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- superset/distributed_lock/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ superset/distributed_lock/types.py:1:1: A005 Module `types` shadows a Python standard-library module
... 18 additional changes omitted for project

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

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

- src/bokeh/application/handlers/code.py:1:1: A005 Module `code` is shadowing a Python builtin module
+ src/bokeh/application/handlers/code.py:1:1: A005 Module `code` shadows a Python standard-library module
- src/bokeh/command/subcommands/json.py:1:1: A005 Module `json` is shadowing a Python builtin module
+ src/bokeh/command/subcommands/json.py:1:1: A005 Module `json` shadows a Python standard-library module
- src/bokeh/core/property/datetime.py:1:1: A005 Module `datetime` is shadowing a Python builtin module
+ src/bokeh/core/property/datetime.py:1:1: A005 Module `datetime` shadows a Python standard-library module
- src/bokeh/core/property/enum.py:1:1: A005 Module `enum` is shadowing a Python builtin module
+ src/bokeh/core/property/enum.py:1:1: A005 Module `enum` shadows a Python standard-library module
- src/bokeh/core/property/json.py:1:1: A005 Module `json` is shadowing a Python builtin module
+ src/bokeh/core/property/json.py:1:1: A005 Module `json` shadows a Python standard-library module
... 20 additional changes omitted for project

latchbio/latch (+8 -8 violations, +0 -0 fixes)

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

- src/latch/functions/secrets.py:1:1: A005 Module `secrets` is shadowing a Python builtin module
+ src/latch/functions/secrets.py:1:1: A005 Module `secrets` shadows a Python standard-library module
- src/latch/registry/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ src/latch/registry/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- src/latch/registry/upstream_types/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ src/latch/registry/upstream_types/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- src/latch/types/glob.py:1:1: A005 Module `glob` is shadowing a Python builtin module
+ src/latch/types/glob.py:1:1: A005 Module `glob` shadows a Python standard-library module
- src/latch/types/json.py:1:1: A005 Module `json` is shadowing a Python builtin module
+ src/latch/types/json.py:1:1: A005 Module `json` shadows a Python standard-library module
... 6 additional changes omitted for project

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

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

- pymilvus/client/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ pymilvus/client/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- pymilvus/orm/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ pymilvus/orm/types.py:1:1: A005 Module `types` shadows a Python standard-library module

yandex/ch-backup (+6 -6 violations, +0 -0 fixes)

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

- ch_backup/compression/gzip.py:1:1: A005 Module `gzip` is shadowing a Python builtin module
+ ch_backup/compression/gzip.py:1:1: A005 Module `gzip` shadows a Python standard-library module
- ch_backup/logging.py:1:1: A005 Module `logging` is shadowing a Python builtin module
+ ch_backup/logging.py:1:1: A005 Module `logging` shadows a Python standard-library module
- ch_backup/profile.py:1:1: A005 Module `profile` is shadowing a Python builtin module
+ ch_backup/profile.py:1:1: A005 Module `profile` shadows a Python standard-library module
- ch_backup/storage/async_pipeline/stages/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ ch_backup/storage/async_pipeline/stages/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- tests/integration/modules/datetime.py:1:1: A005 Module `datetime` is shadowing a Python builtin module
+ tests/integration/modules/datetime.py:1:1: A005 Module `datetime` shadows a Python standard-library module
... 2 additional changes omitted for project

zulip/zulip (+6 -6 violations, +0 -0 fixes)

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

- zerver/actions/typing.py:1:1: A005 Module `typing` is shadowing a Python builtin module
+ zerver/actions/typing.py:1:1: A005 Module `typing` shadows a Python standard-library module
- zerver/lib/profile.py:1:1: A005 Module `profile` is shadowing a Python builtin module
+ zerver/lib/profile.py:1:1: A005 Module `profile` shadows a Python standard-library module
- zerver/lib/queue.py:1:1: A005 Module `queue` is shadowing a Python builtin module
+ zerver/lib/queue.py:1:1: A005 Module `queue` shadows a Python standard-library module
- zerver/lib/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ zerver/lib/types.py:1:1: A005 Module `types` shadows a Python standard-library module
- zerver/lib/url_preview/types.py:1:1: A005 Module `types` is shadowing a Python builtin module
+ zerver/lib/url_preview/types.py:1:1: A005 Module `types` shadows a Python standard-library module
... 2 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
A005 162 81 81 0 0

dcreager added a commit that referenced this pull request Jan 8, 2025
* main:
  [`pylint`] Fix `unreachable` infinite loop (`PLW0101`) (#15278)
  fix invalid syntax in workflow file (#15357)
  [`pycodestyle`] Avoid false positives related to type aliases (`E252`) (#15356)
  [`flake8-builtins`] Disapply `A005` to stub files (#15350)
  Improve logging system using `logLevel`, avoid trace value (#15232)
  [`flake8-builtins`] Rename `A005` and improve its error message (#15348)
  Spruce up docs for pydoclint rules (#15325)
  [`flake8-type-checking`] Apply `TC008` more eagerly in `TYPE_CHECKING` blocks and disapply it in stubs (#15180)
  [red-knot] `knot_extensions` Python API (#15103)
  Display Union of Literals as a Literal (#14993)
  [red-knot] all types are assignable to object (#15332)
  [`ruff`] Parenthesize arguments to `int` when removing `int` would change semantics in `unnecessary-cast-to-int` (`RUF046`) (#15277)
  [`eradicate`] Correctly handle metadata blocks directly followed by normal blocks (`ERA001`) (#15330)
  Narrowing for class patterns in match statements (#15223)
  [red-knot] add call checking (#15200)
  Spruce up docs for `slice-to-remove-prefix-or-suffix` (`FURB188`) (#15328)
  [`internal`] Return statements in finally block point to end block for `unreachable` (`PLW0101`) (#15276)
  [`ruff`] Treat `)` as a regex metacharacter (`RUF043`, `RUF055`) (#15318)
  Use uv consistently throughout the documentation (#15302)
Comment on lines +23 to 24
/// Standard-library modules can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-allowed-modules`] configuration option.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update the settings name as well? (lint.flake8-builtins.builtins-allowed-modules) I think not but thought raise it regardless. Aside, the double "builtins" is a bit unfortunate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good catch. I think we should

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to avoid the rename here and directly rename it to remove the "builtins" prefix from both options. I'll open a tracking issue but happy to hear any suggestions if you think otherwise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants