With dataclasses Rich will essentially replace the dataclass __repr__
by inspecting the dataclass fields. It does this so it can know how to expand the dataclass on to multiple lines with indentation.
For example, here is a dataclass
@dataclass
class DC:
foo: str
bar: int
Rich can inspect the fields and generate this:
DC(
foo="hello",
bar=5
)
However Rich will respect a custom rerpr. For example:
@dataclass
class DC:
foo: str
bar: int
def __repr__(self):
return "DC is better than Marvel"
In the above case, Rich will call repr(dc)
rather than inspecting the fields.
So Rich needs to know if that custom __repr__
is present.
The problem is that the cases with or without the custom __repr__
, the dataclass instances both contain a __repr__
. And Rich needs to know if it is the default one generated by the @dataclass
decorator OR one provided by the user.
Since there is no dataclass base class, I can't just compare it to the baseclasses (via __mro__
). In both cases the mro is (DC, object).
Before Python3.10 the __qualname__
attribute was different in dataclass generated reprs, and I could use that. Now in Python3.10 the __qualname__
attribute is identical in both cases.
Is the
reprlib
module of any help? Or hindrance?