Open jab opened 2 months ago
Note that you can suppress this via https://docs.astral.sh/ruff/settings/#lint_flake8-builtins_builtins-allowed-modules.
I would say it's reasonable to flag these though. What do you think @AlexWaygood?
While we're waiting for others' feedback, I realized I didn't yet provide rationale for why private modules should be excluded from this check, so here is some:
Quoting from ruff's own https://docs.astral.sh/ruff/rules/import-private-name/ rule:
PEP 8 states that names starting with an underscore are private. Thus, they are not intended to be used outside of the module in which they are defined. Further, as private imports are not considered part of the public API, they are prone to unexpected changes, especially outside of semantic versioning.
I'm not sure how much ruff tries to harmonize conflicting rules that users have enabled, but this could be an opportunity to improve harmony.
Also, a lot of the builtin private modules are like _abc
(which is where I hit this), in that:
_abc
, for example, any library that provides its own ABCs might want to put implementation details in its own private _abc.py
)Another interesting observation is that, out of the dozens of private modules in the standard library, https://docs.python.org/3/py-modindex.html documents only two of them, _thread
and _tkinter
, further suggesting that the others are not intended to be directly imported, and outside contexts should also have those names available for internal use.
All that said, I'm fine with just keeping my...
[tool.ruff.lint.flake8-builtins]
builtins-allowed-modules = ["_abc"]
config if it's not worth making any changes here.
I just updated from ruff 0.5.0 to 0.6.1, and had to add an ignore for A005 so that ruff check would continue to pass:
https://github.com/jab/bidict/commit/57a0d0b592c2db2d8114452bb6615dcb1d64876e
Without that ignore, it would fail as follows:
This check is failing because it treats even private builtin modules as not-to-be-shadowed, and Python provides a private
_abc
builtin:I propose that private modules be excluded from this check.