(self, object, stream, indent, allowance, context, level)
| 175 | return readable and not recursive |
| 176 | |
| 177 | def _format(self, object, stream, indent, allowance, context, level): |
| 178 | objid = id(object) |
| 179 | if objid in context: |
| 180 | stream.write(_recursion(object)) |
| 181 | self._recursive = True |
| 182 | self._readable = False |
| 183 | return |
| 184 | rep = self._repr(object, context, level) |
| 185 | max_width = self._width - indent - allowance |
| 186 | if len(rep) > max_width: |
| 187 | p = self._dispatch.get(type(object).__repr__, None) |
| 188 | # Lazy import to improve module import time |
| 189 | from dataclasses import is_dataclass |
| 190 | |
| 191 | if p is not None: |
| 192 | context[objid] = 1 |
| 193 | p(self, object, stream, indent, allowance, context, level + 1) |
| 194 | del context[objid] |
| 195 | return |
| 196 | elif (is_dataclass(object) and |
| 197 | not isinstance(object, type) and |
| 198 | object.__dataclass_params__.repr and |
| 199 | # Check dataclass has generated repr method. |
| 200 | hasattr(object.__repr__, "__wrapped__") and |
| 201 | "__create_fn__" in object.__repr__.__wrapped__.__qualname__): |
| 202 | context[objid] = 1 |
| 203 | self._pprint_dataclass(object, stream, indent, allowance, context, level + 1) |
| 204 | del context[objid] |
| 205 | return |
| 206 | stream.write(rep) |
| 207 | |
| 208 | def _pprint_dataclass(self, object, stream, indent, allowance, context, level): |
| 209 | # Lazy import to improve module import time |
no test coverage detected