from typing import Type
from typing import Any
from typing import Sequence
from typing import get_origin
from typing import get_args


def get_cached_class_args(clazz: Type[Any]) -> tuple[Type[Any], Sequence[Type[Any]]]:
    """
    Helper function to inspect class types.
    For a given class, determine the class to instantiate, and any generic arguments.

    e.g.
    Dict[str, int] -> (dict, (str, int))
    Foo -> (Foo, (,))
    """

    # If the type is generic, this will be the class to use to instantiate
    # This will be None if the class is not generic.
    clazz_origin = get_origin(clazz) or clazz

    # If the type is generic, this will be the generic parameters
    # This will be an empty tuple if the class is not generic.
    clazz_args = get_args(clazz)

    return clazz_origin, clazz_args