from typing import Union


def topic_to_bytes(topic: Union[bytes, str]) -> bytes:
    """
    Return the passed topic as a :class:`bytes` object.
    """
    if isinstance(topic, str):
        topic = topic.encode()
    return topic