ruff
ruff copied to clipboard
`ICN003`: Allow banning all `from` stdlib imports
Our project decided to no longer allow stdlib imports with from due to potentially clashing naming causing confusion.
We are currently resorting to including every stdlib in the flake8-import-conventions banned-from setting:
[tool.ruff.lint.flake8-import-conventions]
banned-from = ["abc", "aifc", "antigravity", "argparse", "array", "ast", "asynchat", "asyncio", "asyncore", "atexit", "..."]
However this is very cumbersome. Is there a possiblity of referencing all stdlib modules? A shortcut like this could perhaps also be used for different importing settings.
I've searched for ICN003, banned-from and banned-import-from, but could not find anything related.
Thanks for the clear write-up!
I would rather go with adding this as a separate rule. @charliermarsh Is this why you marked this with "rule" label?
Why a separate rule if it's the same idea?
cc @AlexWaygood
Is this why you marked this with "rule" label?
(No, the "rule" label can represent either a new rule or a change to an existing rule.)
Why a separate rule if it's the same idea?
This might be a stretch but it could lead to name collisions. So, we could either have "stdlib" as a possible value or maybe provide a new config option for that rule (banned-from-stdlib = true).
I'm curious why the stdlib would be special in terms of "potentially clashing naming causing confusion." What about other third-party libraries? Should the option here really be banned-from-non-first-party?
Maybe banned-from-non-first-party could have "stdlib" as a sentinel to signify only stdlib for that case? Having it as a boolean option alone could mean not having enough granular control over what to ban?