Skip to content

Commit 1bd18df

Browse files
committed
gh-132855: Use overridden custom format for inherited PrettyPrinter
1 parent 4097a92 commit 1bd18df

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Lib/pprint.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,22 @@ def _format(self, object, stream, indent, allowance, context, level):
202202
max_width = self._width - indent - allowance
203203
if len(rep) > max_width:
204204
p = self._dispatch.get(type(object).__repr__, None)
205+
# Lazy import to improve module import time
205206
from dataclasses import is_dataclass
206207

207208
if p is not None:
208209
context[objid] = 1
209-
p(self, object, stream,
210-
indent, allowance, context, level + 1)
210+
p(self, object, stream, indent, allowance, context, level + 1)
211211
del context[objid]
212212
return
213213
elif (is_dataclass(object)
214214
and not isinstance(object, type)
215215
and object.__dataclass_params__.repr
216+
# Check dataclass has generated repr method.
216217
and hasattr(object.__repr__, "__wrapped__")
217218
and "__create_fn__" in object.__repr__.__wrapped__.__qualname__):
218219
context[objid] = 1
219-
self._pprint_dataclass(object, stream,
220-
indent, allowance,
221-
context, level + 1)
220+
self._pprint_dataclass(object, stream, indent, allowance, context, level + 1)
222221
del context[objid]
223222
return
224223

0 commit comments

Comments
 (0)