How to fix inspections etc. for import dynamically __init__.py files adding stuff to globals()?

Answered
In a project I'm working on we have this code in one of our __init__.py files:

for f in os.listdir(os.path.dirname(__file__)):
    if f.endswith('.py'):
        module = importlib.import_module('indico.modules.rb.models.{}'.format(f[:-3]))
        globals().update(module.__dict__)
prettyPrint();

As you can imagine, any imports from that module show up as unresolved references. This is INCREDIBLY annoying. Is there any way to make PyCharm know that any imports from that package can come from any module inside it?
2 comments

The only thing which comes to my mind is to write custom pyi stubs for your code.

0

Please sign in to leave a comment.