import typing


def check_key_type(key: typing.Union[str, bytes]):
    """
    Enforce the type of the key to bytes.

    Parameters
    ----------
    key: str | bytes
        The key to check

    Returns
    -------
    str
        The key as bytes
    """
    if isinstance(key, bytes):
        return key
    return str(key).encode("utf-8")