-
Notifications
You must be signed in to change notification settings - Fork 1.3k
A005 stdlib-module-shadowing warns that utils.logging shadows python logging module #15399
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
Comments
Hi. Thanks for opening the question. This seems to be matching the upstream behavior (more as a note to myself rather than this being a justification why): I'm not 100% sure if this is the right behavior or if the rule is too eager to warn. IMO, the rule should warn if your module is named |
I think this rule should only trigger for modules if there isn't an This is the only way I can see module shadowing being possible, as doing so prepends the parent directory to |
I discussed this with @AlexWaygood in our 1:1 and we think that we should change the default to only flag modules that have the exact same full qualified name as a standard library module and instead, add an option to enable the more strict linting that flags modules that only have the same name. The motivation for an option is that some projects might want stricter behavior to guarantee that modules don't shadow builtins when running a module from a subdirectory (e.g. |
Somehow I can't replicate the problem.
This is perhaps because One thing to note is that
Meanwhile, Is this a bigger bug? |
It triggers if
$ uvx ruff check --isolated --select A005 src
src/test/utils/logging.py:1:1: A005 Module `logging` shadows a Python standard-library module |
Thanks. In that case, this has something to do with the "never- |
interesting that flake8 didnt trigger A005 in this setup BUT ruff did |
OpinionI think that the current rule is too strict, but "only fully qualified names" sounds like it could be too loose, depending on how it's interpreted. In my opinion, any root-level packages that are named the same as any stdlib root-level package should be blocked, along with all their child packages. Example
ReasoningI haven't been around then, but from what I've heard, in the olden days, it wasn't well-defined what However, in modern Python, this issue has been resolved. Additionally, Hope that makes sense :) |
Yeah definitely. This rule has a lot of false positives. |
…5`) (#15951) ## Summary This PR adds the configuration option `lint.flake8-builtins.builtins-strict-checking`, which is used in A005 to determine whether the fully-qualified module name (relative to the project root or source directories) should be checked instead of just the final component as is currently the case. As discussed in #15399 (comment), the default value of the new option is `false` on preview, so modules like `utils.logging` from the initial report are no longer flagged by default. For non-preview the default is still strict checking. ## Test Plan New A005 test module with the structure reported in #15399. Fixes #15399
🎉 |
@ntBre We are having the opposite problem where our CI started emitting more warnings following the latest release of ruff, in places where it wasn't emitting before. Is there documentation somewhere explaining how exactly to turn on the new "default" behavior? |
For those randomly checking here, the new config for
Still not clear to me why an issue which was supposed to reduce the number of default built-in warnings ended up producing more warnings under the default configuration. |
It will be a breaking change to update the stable default, so that will have to wait for the next minor version (0.10.0). In preview mode, the default should already be But yes, as part of this change there was also a bug fix to bring our implementation of A005 in line with the upstream, which does produce more warnings in some cases now. |
Oh and yes, that was my mistake on the documentation. I have an open PR (#16097) to make that easier to find that will hopefully be merged today! |
There's also a related breaking change for 0.10.0 to make the new option and the other flake8-builtins options less verbose in #16092. In this case, I think the new option name will be |
## 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.
## 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.
## 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.
This rule warns for me that
utils.logging
shadows stdliblogging
.Is this intentional? The whole point why our logging module is in
utils
is so the names do not collide. Am I missing something?The text was updated successfully, but these errors were encountered: