def datestr_to_date(
    x: Union[dt.date, str],
    format_str: str = "%Y%m%d",
    *,
    inverse: bool = False,
) -> Union[str, dt.date]:
    """
    Given a string ``x`` representing a date in the given format,
    convert it to a Datetime Date object and return the result.
    If ``inverse``, then assume that ``x`` is a date object and return
    its corresponding string in the given format.
    """
    if x is None:
        return None
    if not inverse:
        result = dt.datetime.strptime(x, format_str).date()
    else:
        result = x.strftime(format_str)
    return result
def datestr_to_date ( x : Union [ dt . date , str ] , format_str : str = "%Y%m%d" , * , inverse : bool = False , ) -> Union [ str , dt . date ] : if x is None : return None if not inverse : result = dt . datetime . strptime ( x , format_str ) . date ( ) else : result = x . strftime ( format_str ) return result
Given a string ``x`` representing a date in the given format,
    convert it to a Datetime Date object and return the result.
    If ``inverse``, then assume that ``x`` is a date object and return
    its corresponding string in the given format.