def _validate_exclusive_arguments()

in nubia/internal/typing/__init__.py [0:0]


def _validate_exclusive_arguments(function, normalized_exclusive_arguments):
    if not normalized_exclusive_arguments:
        return

    exclusive_arguments = normalized_exclusive_arguments
    flat_ex_args = [arg for group in exclusive_arguments for arg in group]

    if not flat_ex_args:
        return

    inspection = inspect_object(function)
    possible_args = list(inspection.arguments.keys())

    unknown_args = set(flat_ex_args) - set(possible_args)
    if unknown_args:
        msg = (
            "The following arguments were specified as exclusive but they "
            "are not present in function {}: {}".format(
                function_to_str(function), ", ".join(unknown_args)
            )
        )
        raise NameError(msg)

    if len(set(flat_ex_args)) != len(flat_ex_args):
        counts = (
            (item, group.count(item)) for group in exclusive_arguments for item in group
        )
        repeated_args = [item for item, count in counts if count > 1]
        msg = (
            "The following args are present in more than one exclusive "
            "group: {}".format(", ".join(repeated_args))
        )
        raise ValueError(msg)