Python typing for module type

Posted on

Question :

Python typing for module type

I am dynamically loading a Python module using importlib.import_module as follows

    def load_module(mod_name: str) -> ???:
        return importlib.import_module(mod_name)

Can somebody tell me what is the correct type annotation for a module type. The typing module does not contain one and I could not find an answer elsewhere.

Answer #1:

You’re looking for types.ModuleType.

Answered By: Aran-Fey

Leave a Reply

Your email address will not be published. Required fields are marked *