optional_import

hcrystalball.utils.optional_import(module_path, class_name, caller_namespace)[source]

Imports optional dependencies.

Imports class from module if importable, otherwise creates dummy class with the same name as requested class. Dummy class fails on init with ModuleNotFound error for the missing dependencies.

Parameters
  • module_name (str) – Path to the module

  • class_name (str) – Name of the class to import/mock

  • caller_namespace (dict, str) – Namespace of the caller

Returns

If importable [class_name] to extend __all__ of the calling module otherwise empty list

Return type

list