from typing import Any
from typing import Optional
from typing import Sequence


def is_allowed_types(value: Any, allowed_types: Optional[Sequence[Any]], required: Optional[bool] = None) -> bool:
    """
    Check whether the type of value is in the allowed types.

    :param value: the value to check the type of
    :param allowed_types: a list of allowed types, to be checked with :func:`isinstance`.
        If *None*, no type check is made.
    :return: whether the type is allowed
    """
    if value is None and required is not None:
        return not required
    if allowed_types is None:
        return True
    tfound = False
    for t in allowed_types:
        if t is None:
            if value is None:
                tfound = True
                break
        elif isinstance(value, t):
            tfound = True
            break
    return tfound