Skip to content

Commit 5060729

Browse files
pprint: Remove tracking of whether an object is readable
This information is not used anywhere
1 parent 767f08c commit 5060729

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

src/_pytest/_io/pprint.py

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def _format(
114114
objid = id(object)
115115
if objid in context:
116116
stream.write(_recursion(object))
117-
self._readable = False
118117
return
119118

120119
p = self._dispatch.get(type(object).__repr__, None)
@@ -486,17 +485,11 @@ def _format_items(
486485
write("\n" + " " * indent)
487486

488487
def _repr(self, object: Any, context: Dict[int, int], level: int) -> str:
489-
repr, readable = self.format(object, context.copy(), self._depth, level)
490-
if not readable:
491-
self._readable = False
492-
return repr
488+
return self.format(object, context.copy(), self._depth, level)
493489

494490
def format(
495491
self, object: Any, context: Dict[int, int], maxlevels: Optional[int], level: int
496-
) -> Tuple[str, bool]:
497-
"""Format object for a specific context, returning a string
498-
and a flag indicating whether the representation is 'readable'.
499-
"""
492+
) -> str:
500493
return self._safe_repr(object, context, maxlevels, level)
501494

502495
def _pprint_default_dict(
@@ -615,30 +608,28 @@ def _pprint_user_string(
615608

616609
def _safe_repr(
617610
self, object: Any, context: Dict[int, int], maxlevels: Optional[int], level: int
618-
) -> Tuple[str, bool]:
619-
# Return pair (repr_string, isreadable).
611+
) -> str:
620612
typ = type(object)
621613
if typ in _builtin_scalars:
622-
return repr(object), True
614+
return repr(object)
623615

624616
r = getattr(typ, "__repr__", None)
625617

626618
if issubclass(typ, int) and r is int.__repr__:
627619
if self._underscore_numbers:
628-
return f"{object:_d}", True
620+
return f"{object:_d}"
629621
else:
630-
return repr(object), True
622+
return repr(object)
631623

632624
if issubclass(typ, dict) and r is dict.__repr__:
633625
if not object:
634-
return "{}", True
626+
return "{}"
635627
objid = id(object)
636628
if maxlevels and level >= maxlevels:
637-
return "{...}", False
629+
return "{...}"
638630
if objid in context:
639-
return _recursion(object), False
631+
return _recursion(object)
640632
context[objid] = 1
641-
readable = True
642633
components: List[str] = []
643634
append = components.append
644635
level += 1
@@ -647,46 +638,41 @@ def _safe_repr(
647638
else:
648639
items = object.items()
649640
for k, v in items:
650-
krepr, kreadable = self.format(k, context, maxlevels, level)
651-
vrepr, vreadable = self.format(v, context, maxlevels, level)
641+
krepr = self.format(k, context, maxlevels, level)
642+
vrepr = self.format(v, context, maxlevels, level)
652643
append(f"{krepr}: {vrepr}")
653-
readable = readable and kreadable and vreadable
654644
del context[objid]
655-
return "{%s}" % ", ".join(components), readable
645+
return "{%s}" % ", ".join(components)
656646

657647
if (issubclass(typ, list) and r is list.__repr__) or (
658648
issubclass(typ, tuple) and r is tuple.__repr__
659649
):
660650
if issubclass(typ, list):
661651
if not object:
662-
return "[]", True
652+
return "[]"
663653
format = "[%s]"
664654
elif len(object) == 1:
665655
format = "(%s,)"
666656
else:
667657
if not object:
668-
return "()", True
658+
return "()"
669659
format = "(%s)"
670660
objid = id(object)
671661
if maxlevels and level >= maxlevels:
672-
return format % "...", False
662+
return format % "..."
673663
if objid in context:
674-
return _recursion(object), False
664+
return _recursion(object)
675665
context[objid] = 1
676-
readable = True
677666
components = []
678667
append = components.append
679668
level += 1
680669
for o in object:
681-
orepr, oreadable = self.format(o, context, maxlevels, level)
670+
orepr = self.format(o, context, maxlevels, level)
682671
append(orepr)
683-
if not oreadable:
684-
readable = False
685672
del context[objid]
686-
return format % ", ".join(components), readable
673+
return format % ", ".join(components)
687674

688-
rep = repr(object)
689-
return rep, bool(rep and not rep.startswith("<"))
675+
return repr(object)
690676

691677

692678
_builtin_scalars = frozenset({str, bytes, bytearray, float, complex, bool, type(None)})

0 commit comments

Comments
 (0)