def _ordering_tuple(self):
    """Builds a tuple that can be used to compare this object to other types."""
    assert dataclasses.is_dataclass(self)
    # Arbitrarily order types by their name, module, and then the id of their
    # type if necessary.
    order_parts = [
        type(self).__qualname__,
        type(self).__module__,
        id(type(self)),
    ]
    # Within a given type, order by the values of the fields, like for an
    # ordinary ordered dataclass.
    for field in dataclasses.fields(self):
      if field.compare:
        order_parts.append(getattr(self, field.name))
    return tuple(order_parts)
Builds a tuple that can be used to compare this object to other types.
penzai/core/auto_order_types.py