ruff icon indicating copy to clipboard operation
ruff copied to clipboard

`ICN003`: Allow banning all `from` stdlib imports

Open Grub4K opened this issue 1 year ago • 6 comments

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.

Grub4K avatar Mar 29 '24 22:03 Grub4K

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?

dhruvmanila avatar Apr 01 '24 08:04 dhruvmanila

Why a separate rule if it's the same idea?

cc @AlexWaygood

zanieb avatar Apr 02 '24 02:04 zanieb

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.)

charliermarsh avatar Apr 02 '24 03:04 charliermarsh

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).

dhruvmanila avatar Apr 05 '24 10:04 dhruvmanila

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?

carljm avatar Apr 05 '24 14:04 carljm

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?

Grub4K avatar Apr 05 '24 18:04 Grub4K