PyCharm Editor import assistant uses __init__.py instead of original source file Follow
Hi experts,
I have a problem with the PyCharm Editor import assistant. I'm developing a library package with many sub-modules in sub-directories. I often include classes from from low level sub-modules into higher level sub-modules.
The assistant works fine as long I have no top level __init__.py file. The original sub-modules are found and used for the import statement. But when I add "import ..." statements and an "__all__ = [...]" variable to the top-level __init__.py, the original source file is no longer used by the assistant, instead the top level __init__.py is used.
This behavior is fine for consumers of the library, but not for the developer of the library itself. It leads very quickly to "circular import" errors.
Any idea how I can configure PyCharm to use the original source files with import statements when inside a library source file? I have a simple project attached, how it can be found with the ID below. (See src/sample/module_a/ma_first.py for details).
Kind regards, Andi
Upload id: 2021_08_26_JmoShrQH7yAHEF88 (file: pycharm-import-problem-example.zip)
Please sign in to leave a comment.
Hi, thank you for the clear sample project.
Unfortunately, I don't think this is configurable. Taking your example, PyCharm uses the shortest path for auto-import, and from the first glance, I don't see an issue with this.
I think the best course of action is to submit a usability problem to our issue tracker with this project sample, plus the sample of circular import issue resulting from it.