def safe_repr(x):
    """
    A repr() that never fails, even if object has some bad implementation.
    """
    try:
        return repr(x)
    except:
        name = getattr(type(x), "__name__", "object")
        return f"<{name} instance>"