def find_class_in_module(module: ModuleType, cls_type: Type[ClassType]) -> Optional[Type[ClassType]]:
    """Try to find the implementation of *cls_type* class interface in *module* matching the *module* name.

    :param module: imported module.
    :param cls_type: a class type we are looking for.

    :returns: class with a name matching the name of *module* that implements *cls_type* or ``None`` if not found.
    """
    module_name = module.__name__.rpartition('.')[2]
    return next(
        (obj for obj_name, obj in module.__dict__.items()
         if (obj_name.lower() == module_name
             and inspect.isclass(obj) and issubclass(obj, cls_type))),
        None)
Try to find the implementation of *cls_type* class interface in *module* matching the *module* name.

    :param module: imported module.
    :param cls_type: a class type we are looking for.

    :returns: class with a name matching the name of *module* that implements *cls_type* or ``None`` if not found.
    
patroni/dynamic_loader.py