def check_or_get_instance(ins_or_class_or_name, kwargs, module_paths=None, classtype=None):
    'Returns a class instance and checks types.\n\n    Args:\n        ins_or_class_or_name: Can be of 3 types:\n\n            - A class to instantiate.\n            - A string of the name or full path to a class to               instantiate.\n            - The class instance to check types.\n\n        kwargs (dict): Keyword arguments for the class constructor. Ignored\n            if `ins_or_class_or_name` is a class instance.\n        module_paths (list, optional): Paths to candidate modules to\n            search for the class. This is used if the class cannot be\n            located solely based on :attr:`class_name`. The first module\n            in the list that contains the class is used.\n        classtype (optional): A (list of) class of which the instance must\n            be an instantiation.\n\n    Raises:\n        ValueError: If class is not found based on :attr:`class_name` and\n            :attr:`module_paths`.\n        ValueError: If :attr:`kwargs` contains arguments that are invalid\n            for the class construction.\n        TypeError: If the instance is not an instantiation of\n            :attr:`classtype`.\n    '
    ret = ins_or_class_or_name
    if (is_str(ret) or isinstance(ret, type)):
        ret = get_instance(ret, kwargs, module_paths)
    if (classtype is not None):
        if (not isinstance(ret, classtype)):
            raise TypeError('An instance of {} is expected. Got: {}'.format(classtype, ret))
    return ret
Returns a class instance and checks types.

Args:
    ins_or_class_or_name: Can be of 3 types:

        - A class to instantiate.
        - A string of the name or full path to a class to               instantiate.
        - The class instance to check types.

    kwargs (dict): Keyword arguments for the class constructor. Ignored
        if `ins_or_class_or_name` is a class instance.
    module_paths (list, optional): Paths to candidate modules to
        search for the class. This is used if the class cannot be
        located solely based on :attr:`class_name`. The first module
        in the list that contains the class is used.
    classtype (optional): A (list of) class of which the instance must
        be an instantiation.

Raises:
    ValueError: If class is not found based on :attr:`class_name` and
        :attr:`module_paths`.
    ValueError: If :attr:`kwargs` contains arguments that are invalid
        for the class construction.
    TypeError: If the instance is not an instantiation of
        :attr:`classtype`.
def check_or_get_instance(ins_or_class_or_name, kwargs, module_paths=None, classtype=None):
    'Returns a class instance and checks types.\n\n    Args:\n        ins_or_class_or_name: Can be of 3 types:\n\n            - A class to instantiate.\n            - A string of the name or full path to a class to               instantiate.\n            - The class instance to check types.\n\n        kwargs (dict): Keyword arguments for the class constructor. Ignored\n            if `ins_or_class_or_name` is a class instance.\n        module_paths (list, optional): Paths to candidate modules to\n            search for the class. This is used if the class cannot be\n            located solely based on :attr:`class_name`. The first module\n            in the list that contains the class is used.\n        classtype (optional): A (list of) class of which the instance must\n            be an instantiation.\n\n    Raises:\n        ValueError: If class is not found based on :attr:`class_name` and\n            :attr:`module_paths`.\n        ValueError: If :attr:`kwargs` contains arguments that are invalid\n            for the class construction.\n        TypeError: If the instance is not an instantiation of\n            :attr:`classtype`.\n    '
    ret = ins_or_class_or_name
    if (is_str(ret) or isinstance(ret, type)):
        ret = get_instance(ret, kwargs, module_paths)
    if (classtype is not None):
        if (not isinstance(ret, classtype)):
            raise TypeError('An instance of {} is expected. Got: {}'.format(classtype, ret))
    return ret