import uuid
from typing import Union
import hashlib


def uuid5(namespace: uuid.UUID, name: Union[str, bytes]) -> uuid.UUID:
    """Generate a UUID from the SHA-1 hash of a namespace UUID and a name.

    Unlike the stdlib version, the name can be bytes. If it is a str, this function delgates to the stdlib.

    :param namespace: The UUID namespace identifier
    :param name: The name, which is a str or bytes

    :returns: The UUID version 5
    """
    if isinstance(name, str):
        return uuid.uuid5(namespace, name)
    else:
        hash = hashlib.sha1(namespace.bytes + name).digest()
        return uuid.UUID(bytes=hash[:16], version=5)