from typing import Optional


def has_space(
    enclosing_string: str,
    idx: int,
    preceeding: bool = True,
    prev_str: Optional[str] = None,
) -> bool:
    """Returns whether there is a space preceeding/following(based on whether preceeding is True or False respectively)
    idx in the enclosing_string, which may optionally have a prev_str concatenated to its immediate left.
    It is assumed nothing to the right of enclosing_string.
    """
    if preceeding:
        return (idx == 0 and (True if prev_str is None else prev_str[-1]
                              == " ")) or enclosing_string[idx - 1] == " "

    return idx == len(enclosing_string) - 1 or enclosing_string[idx + 1] == " "