import binascii


def to_hex(data):
    """Converts bytes to hex if not None
    """
    if data is None:
        return None
    if not isinstance(data, bytes):
        raise TypeError("Expect bytes")
    return binascii.b2a_hex(data).decode("ascii")