def _import_module(self, modname: str, required: bool) -> NewExtensionModule:
    if (modname in self.modules):
        return self.modules[modname]
    try:
        module = importlib.import_module(('mesonbuild.modules.' + modname))
    except ImportError:
        if required:
            raise InvalidArguments(f'Module "{modname}" does not exist')
        ext_module = NotFoundExtensionModule()
    else:
        ext_module = module.initialize(self)
        assert isinstance(ext_module, (ExtensionModule, NewExtensionModule))
        self.build.modules.append(modname)
    self.modules[modname] = ext_module
    return ext_module
def _import_module(self, modname: str, required: bool) -> NewExtensionModule:
    if (modname in self.modules):
        return self.modules[modname]
    try:
        module = importlib.import_module(('mesonbuild.modules.' + modname))
    except ImportError:
        if required:
            raise InvalidArguments(f'Module "{modname}" does not exist')
        ext_module = NotFoundExtensionModule()
    else:
        ext_module = module.initialize(self)
        assert isinstance(ext_module, (ExtensionModule, NewExtensionModule))
        self.build.modules.append(modname)
    self.modules[modname] = ext_module
    return ext_module