import typing


def is_type(input_object, expected_type) -> bool:
    """
    Check if an object corresponds to a given type.

    Works similarly to isinstance but also works on select 'typing' types.
    """
    try:
        module = expected_type.__module__
    except AttributeError:
        module = "default"

    if module == "typing":

        if isinstance(input_object, dict):
            right_types = []
            for key, value in input_object.items():
                right_types.append(
                    all([
                        isinstance(key, expected_type.__args__[0]),
                        isinstance(value, expected_type.__args__[1])
                    ])
                )
            return all(right_types)

        if isinstance(input_object, (list, tuple)):
            accepted_types = expected_type.__args__
            if not isinstance(accepted_types, list):
                accepted_types = [accepted_types] * len(input_object)

            right_types = [is_type(element, accepted_types[i]) for i, element in enumerate(input_object)]

            return all(right_types)

        if expected_type.__origin__ == typing.Union:
            for accepted_type in expected_type.__args__:
                if isinstance(input_object, accepted_type):
                    return True

        return False
    if input_object is None:
        if expected_type is None:
            return True
        return False
    return isinstance(input_object, expected_type)