def get_instance(class_or_name, kwargs, module_paths=None):
    'Creates a class instance.\n\n    Args:\n        class_or_name: A class, or its name or full path to a class to\n            instantiate.\n        kwargs (dict): Keyword arguments for the class constructor.\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\n    Returns:\n        A class instance.\n\n    Raises:\n        ValueError: If class is not found based on :attr:`class_or_name` and\n            :attr:`module_paths`.\n        ValueError: If :attr:`kwargs` contains arguments that are invalid\n            for the class construction.\n    '
    class_ = class_or_name
    if is_str(class_):
        class_ = get_class(class_, module_paths)
    class_args = set(get_args(class_.__init__))
    if (kwargs is None):
        kwargs = {}
    for key in kwargs.keys():
        if (key not in class_args):
            raise ValueError(('Invalid argument for class %s.%s: %s, valid args: %s' % (class_.__module__, class_.__name__, key, list(class_args))))
    return class_(**kwargs)
Creates a class instance.

Args:
    class_or_name: A class, or its name or full path to a class to
        instantiate.
    kwargs (dict): Keyword arguments for the class constructor.
    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.

Returns:
    A class instance.

Raises:
    ValueError: If class is not found based on :attr:`class_or_name` and
        :attr:`module_paths`.
    ValueError: If :attr:`kwargs` contains arguments that are invalid
        for the class construction.
def get_instance(class_or_name, kwargs, module_paths=None):
    'Creates a class instance.\n\n    Args:\n        class_or_name: A class, or its name or full path to a class to\n            instantiate.\n        kwargs (dict): Keyword arguments for the class constructor.\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\n    Returns:\n        A class instance.\n\n    Raises:\n        ValueError: If class is not found based on :attr:`class_or_name` and\n            :attr:`module_paths`.\n        ValueError: If :attr:`kwargs` contains arguments that are invalid\n            for the class construction.\n    '
    class_ = class_or_name
    if is_str(class_):
        class_ = get_class(class_, module_paths)
    class_args = set(get_args(class_.__init__))
    if (kwargs is None):
        kwargs = {}
    for key in kwargs.keys():
        if (key not in class_args):
            raise ValueError(('Invalid argument for class %s.%s: %s, valid args: %s' % (class_.__module__, class_.__name__, key, list(class_args))))
    return class_(**kwargs)