Forbid self imports
There's a very useful feature in pylint called self-import.
What it does?
It disallows to write code as this one:
# ex.py
import ex # self import
from ex import * # self import
print('init!')
I guess it might be a good idea to forbid this kind of imports by import-linter.
I have tried to implement it inside wemake-python-styleguide, but I am not sure that it is the best place to do it.
Original: https://github.com/wemake-services/wemake-python-styleguide/issues/699
What do you think?
Hi Nikita,
Thanks, as always, for the suggestion!
I'm unclear about whether or not self imports are a real problem. How often does this kind of thing actually happen? I'd be interested to hear more on this.
In terms of whether it's right for Import Linter, I feel the main focus should be on architecture, focusing on the dependency relationships between modules. The import statements themselves are more of a proxy for those relationships. I'm leaning towards not including linting for style, or even straightforward mistakes like this. I reckon that kind of thing could probably be done by a different kind of tool, that doesn't need the overhead of building an entire dependency graph.
Happy to hear more about it though.
My guess is that import-linter is about imports 🙂
However, I like the focus of this library. It is unique and useful.
Considering self-imports: I have never seen one in a real-life code. But, the ability to do it seems like a possibility for all kinds of mistakes (including possible ones in the import graph, because they create self-cycles).
I guess that some sanity-checking is a good thing. Like:
- self imports
- explicit import cycles
I'm going to close this ticket as it's quite old, and I think that it's best to keep import linter architecture-focused. I think it is probably possible to support this via a custom contract type, which could always be released as a separate package.