code: def import_optional(
      module_name: str, names: Optional[List[str]] = None
  ) -> Any:
      """Import a module that depends on optional dependencies
  
      Note: This function is used to import modules that depend on optional dependencies. Because it mirrors the python
      import functionality its return type has to be `Any`. Using objects imported with this function can lead to
      misspecification of types as `Any` when the developer intended to be more restrictive.
  
      Parameters
      ----------
      module_name
          The module to import
      names
          The names to import from the module. If None, all names are imported.
  
      Returns
      -------
      The module or named objects within the modules if names is not None. If the import fails due to a
      ModuleNotFoundError or ImportError then the requested module or named objects are replaced with instances of
      the MissingDependency class above.
      """
  
      try:
          module = import_module(module_name)
          # TODO: We should check against specific dependency versions here.
          if names is not None:
              objs = tuple(getattr(module, name) for name in names)
              return objs if len(objs) > 1 else objs[0]
          return module
      except (ImportError, ModuleNotFoundError) as err:
          if err.name is None:
              raise err
          name, *_ = err.name.split(".")
          if name not in ERROR_TYPES:
              raise err
          missing_dependency = ERROR_TYPES[name]
          if names is not None:
              missing_dependencies = tuple(
                  MissingDependency(
                      missing_dependency=missing_dependency,
                      object_name=name,
                      err=err,
                  )
                  for name in names
              )
              return (
                  missing_dependencies
                  if len(missing_dependencies) > 1
                  else missing_dependencies[0]
              )
          return MissingDependency(
              missing_dependency=missing_dependency,
              object_name=module_name,
              err=err,
          )
  
file_path: alibi/alibi/utils/missing_optional_dependency.py
imports: from typing import Union, List, Optional, Any
  from string import Template
  from importlib import import_module
label_desc: Use image node_id 1 for calling a global function with example usage: import_optional(module_name, names) and returns: module, unknown, MissingDependency, unknown