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

In a project I'm working on we have this code in one of our 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]))

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.