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

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?

Please sign in to leave a comment.