def _check_type(obj, base, allow_none):
    """Check whether an object is an instance of a base type.

    Parameters
    ----------
    obj : object
        The object to be validated.

    base : type
        The base type that `obj` should be an instance of.

    allow_none : bool
        Indicates whether the value None should be allowed to pass through.

    Returns
    -------
    obj : base type or None
        The validated object.

    Raises
    ------
    TypeError
        If `obj` is not an instance of `base`.
    """
    if allow_none and obj is None:
        return None
    if isinstance(obj, base):
        return obj
    expect = base.__name__
    actual = type(obj).__name__
    raise TypeError(f'Invalid type. Expected: {expect}. Actual: {actual}.')
