chainalysis.util_functions.check_list_type - Data Solutions Python SDK 0.7.0 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
Toggle table of contents sidebar

# Source code for chainalysis.util_functions.check_list_type

    from typing import Any, List, Type

    from chainalysis.exceptions import BadRequest

    def get_list_type(_list: List[Any]) -> Type:
        """
        Return the type of list elements if all are the same type, otherwise raise an error.
        """
        if not _list:
            raise ValueError("The list is empty and has no element type.")

        element_types = {type(item) for item in _list}

        if len(element_types) > 1:
            raise BadRequest(
                f"The list contains multiple types: {element_types}. Enter a list with only numbers, strings, or bools."
            )

        return element_types.pop()