Skip to content

[flake8-builtins] Match upstream module name comparison (A005) - #16006

Merged
ntBre merged 2 commits into
mainfrom
brent/a005-bugfix
Feb 7, 2025
Merged

[flake8-builtins] Match upstream module name comparison (A005)#16006
ntBre merged 2 commits into
mainfrom
brent/a005-bugfix

Conversation

@ntBre

@ntBre ntBre commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

See #15951 for the original discussion and reviews. This is just the first half of that PR (reaching parity with flake8-builtins without adding any new configuration options) split out for nicer changelog entries.

For posterity, here's a script for generating the module structure that was useful for interactive testing and creating the table here. The results for this branch are the same as the Strict column there, as expected.

mkdir abc collections foobar urlparse

for i in */
do
	touch $i/__init__.py
done	

cp -r abc foobar collections/.
cp -r abc collections foobar/.

touch ruff.toml

touch foobar/logging.py

See #15951 for the original discussion and reviews. This is just the first half
of that PR (reaching parity with `flake8-builtins` without adding any new
configuration options) split out for nicer changelog entries.
@ntBre ntBre added bug Something isn't working rule Implementing or modifying a lint rule labels Feb 6, 2025
Comment thread crates/ruff/tests/lint.rs
Comment thread crates/ruff/tests/lint.rs
@github-actions

github-actions Bot commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

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

apache/airflow (+20 -8 violations, +0 -0 fixes)

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

+ airflow/api_fastapi/logging/__init__.py:1:1: A005 Module `logging` shadows a Python standard-library module
+ airflow/io/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ airflow/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
- providers/common/io/src/airflow/providers/common/io/assets/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
- providers/common/io/src/airflow/providers/common/io/assets/assets/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
- providers/common/io/src/airflow/providers/common/io/operators/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
- providers/common/io/src/airflow/providers/common/io/xcom/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ providers/common/io/tests/provider_tests/common/io/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ providers/google/src/airflow/providers/google/cloud/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/google/tests/provider_tests/google/cloud/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/hashicorp/src/airflow/providers/hashicorp/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/hashicorp/tests/provider_tests/hashicorp/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
- providers/http/src/airflow/providers/http/hooks/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
- providers/http/src/airflow/providers/http/operators/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
- providers/http/src/airflow/providers/http/sensors/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
- providers/http/src/airflow/providers/http/triggers/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
+ providers/http/tests/provider_tests/http/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
+ providers/opsgenie/src/airflow/providers/opsgenie/typing/__init__.py:1:1: A005 Module `typing` shadows a Python standard-library module
+ providers/opsgenie/tests/provider_tests/opsgenie/typing/__init__.py:1:1: A005 Module `typing` shadows a Python standard-library module
+ providers/src/airflow/providers/amazon/aws/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/src/airflow/providers/microsoft/azure/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/tests/amazon/aws/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/tests/email/__init__.py:1:1: A005 Module `email` shadows a Python standard-library module
+ providers/tests/microsoft/azure/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/yandex/src/airflow/providers/yandex/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/yandex/tests/provider_tests/yandex/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ tests/io/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ tests/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module

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

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

+ examples/interaction/widgets/fileinput.py:1:1: A005 Module `fileinput` shadows a Python standard-library module
+ src/bokeh/io/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ src/bokeh/models/annotations/html/__init__.py:1:1: A005 Module `html` shadows a Python standard-library module

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

+ src/latch/idl/core/types.py:1:1: A005 Module `types` shadows a Python standard-library module
+ src/latch/types/__init__.py:1:1: A005 Module `types` shadows a Python standard-library module

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

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

+ zerver/webhooks/json/__init__.py:1:1: A005 Module `json` shadows a Python standard-library module

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
A005 34 26 8 0 0

Linter (preview)

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

apache/airflow (+20 -8 violations, +0 -0 fixes)

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

+ airflow/api_fastapi/logging/__init__.py:1:1: A005 Module `logging` shadows a Python standard-library module
+ airflow/io/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ airflow/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
- providers/common/io/src/airflow/providers/common/io/assets/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
- providers/common/io/src/airflow/providers/common/io/assets/assets/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
- providers/common/io/src/airflow/providers/common/io/operators/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
- providers/common/io/src/airflow/providers/common/io/xcom/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ providers/common/io/tests/provider_tests/common/io/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ providers/google/src/airflow/providers/google/cloud/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/google/tests/provider_tests/google/cloud/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/hashicorp/src/airflow/providers/hashicorp/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/hashicorp/tests/provider_tests/hashicorp/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
- providers/http/src/airflow/providers/http/hooks/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
- providers/http/src/airflow/providers/http/operators/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
- providers/http/src/airflow/providers/http/sensors/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
- providers/http/src/airflow/providers/http/triggers/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
+ providers/http/tests/provider_tests/http/__init__.py:1:1: A005 Module `http` shadows a Python standard-library module
+ providers/opsgenie/src/airflow/providers/opsgenie/typing/__init__.py:1:1: A005 Module `typing` shadows a Python standard-library module
+ providers/opsgenie/tests/provider_tests/opsgenie/typing/__init__.py:1:1: A005 Module `typing` shadows a Python standard-library module
+ providers/src/airflow/providers/amazon/aws/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/src/airflow/providers/microsoft/azure/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/tests/amazon/aws/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/tests/email/__init__.py:1:1: A005 Module `email` shadows a Python standard-library module
+ providers/tests/microsoft/azure/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/yandex/src/airflow/providers/yandex/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ providers/yandex/tests/provider_tests/yandex/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module
+ tests/io/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ tests/secrets/__init__.py:1:1: A005 Module `secrets` shadows a Python standard-library module

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

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

+ examples/interaction/widgets/fileinput.py:1:1: A005 Module `fileinput` shadows a Python standard-library module
+ src/bokeh/io/__init__.py:1:1: A005 Module `io` shadows a Python standard-library module
+ src/bokeh/models/annotations/html/__init__.py:1:1: A005 Module `html` shadows a Python standard-library module

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

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

+ src/latch/idl/core/types.py:1:1: A005 Module `types` shadows a Python standard-library module
+ src/latch/types/__init__.py:1:1: A005 Module `types` shadows a Python standard-library module

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

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

+ zerver/webhooks/json/__init__.py:1:1: A005 Module `json` shadows a Python standard-library module

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
A005 34 26 8 0 0

@ntBre
ntBre requested a review from MichaReiser February 6, 2025 23:04

@MichaReiser MichaReiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for taking the time to split this into its own PR!

Comment thread crates/ruff/tests/lint.rs
Comment thread crates/ruff/tests/lint.rs
Comment thread crates/ruff_linter/src/rules/flake8_builtins/rules/stdlib_module_shadowing.rs Outdated
Co-authored-by: Micha Reiser <micha@reiser.io>
@ntBre

ntBre commented Feb 7, 2025

Copy link
Copy Markdown
Contributor Author

I just did a manual is_none_or to avoid any MSRV problems, and I'm currently leaning toward just leaving the tests as they are. Once this is merged, I will rebase my other PR onto it!

@ntBre
ntBre merged commit d4a5772 into main Feb 7, 2025
@ntBre
ntBre deleted the brent/a005-bugfix branch February 7, 2025 18:55
ntBre added a commit that referenced this pull request Feb 26, 2025
Summary
--
This resolves a TODO I left behind in #16006 now that our MSRV is 1.83.

Test Plan
--
Existing tests
ntBre added a commit that referenced this pull request Feb 26, 2025
Summary
--
This resolves a TODO I left behind in #16006 now that our MSRV is 1.83.

Test Plan
--
Existing tests
ntBre added a commit that referenced this pull request Mar 11, 2025
## Summary

This PR changes the default value of
`lint.flake8-builtins.builtins-strict-checking` added in
#15951 from `true` to `false`.
This also allows simplifying the default option logic and removes the
dependence on preview mode.

#15399 was already closed by
#15951, but this change will finalize the behavior mentioned in
#15399 (comment).

As an example, strict checking flags modules based on their last
component, so `utils/logging.py` triggers A005. Non-strict checking
checks the path to the module, so `utils/logging.py` is allowed (this is
the example and desired behavior from #15399 exactly) but a top-level
`logging.py` or `logging/__init__.py` is still disallowed.

## Test Plan

Existing tests from #15951 and #16006, with the snapshot updated in
`a005_module_shadowing_strict_default` to reflect the new default.
MichaReiser pushed a commit that referenced this pull request Mar 13, 2025
## Summary

This PR changes the default value of
`lint.flake8-builtins.builtins-strict-checking` added in
#15951 from `true` to `false`.
This also allows simplifying the default option logic and removes the
dependence on preview mode.

#15399 was already closed by
#15951, but this change will finalize the behavior mentioned in
#15399 (comment).

As an example, strict checking flags modules based on their last
component, so `utils/logging.py` triggers A005. Non-strict checking
checks the path to the module, so `utils/logging.py` is allowed (this is
the example and desired behavior from #15399 exactly) but a top-level
`logging.py` or `logging/__init__.py` is still disallowed.

## Test Plan

Existing tests from #15951 and #16006, with the snapshot updated in
`a005_module_shadowing_strict_default` to reflect the new default.
MichaReiser pushed a commit that referenced this pull request Mar 13, 2025
## Summary

This PR changes the default value of
`lint.flake8-builtins.builtins-strict-checking` added in
#15951 from `true` to `false`.
This also allows simplifying the default option logic and removes the
dependence on preview mode.

#15399 was already closed by
#15951, but this change will finalize the behavior mentioned in
#15399 (comment).

As an example, strict checking flags modules based on their last
component, so `utils/logging.py` triggers A005. Non-strict checking
checks the path to the module, so `utils/logging.py` is allowed (this is
the example and desired behavior from #15399 exactly) but a top-level
`logging.py` or `logging/__init__.py` is still disallowed.

## Test Plan

Existing tests from #15951 and #16006, with the snapshot updated in
`a005_module_shadowing_strict_default` to reflect the new default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants