Skip to content

Commit

Permalink
fix pprint to preserve the original
Browse files Browse the repository at this point in the history
  • Loading branch information
boeddeker committed May 29, 2024
1 parent 8f098af commit cab3760
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion paderbox/utils/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ def _dataclass_repr_pretty_(self, p, cycle):
)
>>> pprint(PointClsWithALongName(1, 2), max_width=len('PointClsWithALongName') + 10)
PointClsWithALongName(x=1, y=2)
>>> @dataclasses.dataclass
... class PrettyPoint:
... x: int
... y: int
... def _repr_pretty_(self, p, cycle):
... p.text(f'CustomRepr(x={self.x}, y={self.y})')
>>> pprint(PrettyPoint(1, 2))
CustomRepr(x=1, y=2)
"""
if cycle:
p.text(f'{self.__class__.__name__}(...)')
Expand All @@ -133,7 +143,7 @@ def _dataclass_repr_pretty_(self, p, cycle):
p.text(')')

def _in_deferred_types(self, cls):
if dataclasses.is_dataclass(cls):
if '_repr_pretty_' not in cls.__dict__ and dataclasses.is_dataclass(cls):
return self._dataclass_repr_pretty_
else:
return super()._in_deferred_types(cls)
Expand Down

0 comments on commit cab3760

Please sign in to comment.