def iter_classes(
        package: str, cls_type: Type[ClassType],
        config: Optional[Union['Config', Dict[str, Any]]] = None
) -> Iterator[Tuple[str, Type[ClassType]]]:
    """Attempt to import modules and find implementations of *cls_type* that are present in the given configuration.

    .. note::
            If a module successfully imports we can assume that all its requirements are installed.

    :param package: a package name to search modules in, e.g. ``patroni.dcs``.
    :param cls_type: a class type we are looking for.
    :param config: configuration information with possible module names as keys. If given, only attempt to import
                   modules defined in the configuration. Else, if ``None``, attempt to import any supported module.

    :yields: a tuple containing the module ``name`` and the imported class object.
    """
    for mod_name in iter_modules(package):
        name = mod_name.rpartition('.')[2]
        if config is None or name in config:
            try:
                module = importlib.import_module(mod_name)
                module_cls = find_class_in_module(module, cls_type)
                if module_cls:
                    yield name, module_cls
            except ImportError:
                logger.log(logging.DEBUG if config is not None else logging.INFO,
                           'Failed to import %s', mod_name)
Attempt to import modules and find implementations of *cls_type* that are present in the given configuration.

    .. note::
            If a module successfully imports we can assume that all its requirements are installed.

    :param package: a package name to search modules in, e.g. ``patroni.dcs``.
    :param cls_type: a class type we are looking for.
    :param config: configuration information with possible module names as keys. If given, only attempt to import
                   modules defined in the configuration. Else, if ``None``, attempt to import any supported module.

    :yields: a tuple containing the module ``name`` and the imported class object.
    
patroni/dynamic_loader.py