defget_object_from_module_string(module_string:str)->Any:try:module_string,object_name=module_string.rsplit('.',1)module=__import__(module_string,fromlist=[object_name])exceptImportErrorase:message=f'Could not import module: {module_string}'raiseImportError(message)fromereturngetattr(module,object_name)
defget_callable_from_module_string_and_validate_arguments(module_string:str,valid_args:Sequence[str])->Callable:callable_=get_object_from_module_string(module_string)ifnotcallable(callable_):message=f'Object {module_string} is not callable'raiseTypeError(message)sig=inspect.signature(callable_)params=sig.parametersfornameinvalid_args:ifnamenotinparams:message=f'{callable_.__qualname__} is missing required argument: {name}'raiseTypeError(message)returncallable_