from datetime import datetime
from typing import Literal


def get_shift(date: datetime) -> Literal["1", "2", "3", "?"]:
    """
    According to the time, it is assigned the shift
    07:00 - 14:59 = 1
    15:00 - 22:59 = 2
    23:00 - 06:59 = 3

    Args:
        date:
            Python datetime, extract the hour an eval

    Returns:
        Return a string with the corresponding shift; 1,2,3 or ?
    """

    try:
        hour = date.hour
    except AttributeError:
        # If date is not datetime like None or str set hour to -1
        hour = -1

    # By default shift is equal to ? and override in the conditional block
    shift = "?"

    if hour >= 7 and hour <= 14:
        shift = "1"
    elif hour >= 15 and hour <= 22:
        shift = "2"
    elif (hour >= 0 and hour <= 7) or hour >= 23:
        shift = "3"

    return shift