@@ -114,7 +114,6 @@ def _format(
114
114
objid = id (object )
115
115
if objid in context :
116
116
stream .write (_recursion (object ))
117
- self ._readable = False
118
117
return
119
118
120
119
p = self ._dispatch .get (type (object ).__repr__ , None )
@@ -486,17 +485,11 @@ def _format_items(
486
485
write ("\n " + " " * indent )
487
486
488
487
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 )
493
489
494
490
def format (
495
491
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 :
500
493
return self ._safe_repr (object , context , maxlevels , level )
501
494
502
495
def _pprint_default_dict (
@@ -615,30 +608,28 @@ def _pprint_user_string(
615
608
616
609
def _safe_repr (
617
610
self , object : Any , context : Dict [int , int ], maxlevels : Optional [int ], level : int
618
- ) -> Tuple [str , bool ]:
619
- # Return pair (repr_string, isreadable).
611
+ ) -> str :
620
612
typ = type (object )
621
613
if typ in _builtin_scalars :
622
- return repr (object ), True
614
+ return repr (object )
623
615
624
616
r = getattr (typ , "__repr__" , None )
625
617
626
618
if issubclass (typ , int ) and r is int .__repr__ :
627
619
if self ._underscore_numbers :
628
- return f"{ object :_d} " , True
620
+ return f"{ object :_d} "
629
621
else :
630
- return repr (object ), True
622
+ return repr (object )
631
623
632
624
if issubclass (typ , dict ) and r is dict .__repr__ :
633
625
if not object :
634
- return "{}" , True
626
+ return "{}"
635
627
objid = id (object )
636
628
if maxlevels and level >= maxlevels :
637
- return "{...}" , False
629
+ return "{...}"
638
630
if objid in context :
639
- return _recursion (object ), False
631
+ return _recursion (object )
640
632
context [objid ] = 1
641
- readable = True
642
633
components : List [str ] = []
643
634
append = components .append
644
635
level += 1
@@ -647,46 +638,41 @@ def _safe_repr(
647
638
else :
648
639
items = object .items ()
649
640
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 )
652
643
append (f"{ krepr } : { vrepr } " )
653
- readable = readable and kreadable and vreadable
654
644
del context [objid ]
655
- return "{%s}" % ", " .join (components ), readable
645
+ return "{%s}" % ", " .join (components )
656
646
657
647
if (issubclass (typ , list ) and r is list .__repr__ ) or (
658
648
issubclass (typ , tuple ) and r is tuple .__repr__
659
649
):
660
650
if issubclass (typ , list ):
661
651
if not object :
662
- return "[]" , True
652
+ return "[]"
663
653
format = "[%s]"
664
654
elif len (object ) == 1 :
665
655
format = "(%s,)"
666
656
else :
667
657
if not object :
668
- return "()" , True
658
+ return "()"
669
659
format = "(%s)"
670
660
objid = id (object )
671
661
if maxlevels and level >= maxlevels :
672
- return format % "..." , False
662
+ return format % "..."
673
663
if objid in context :
674
- return _recursion (object ), False
664
+ return _recursion (object )
675
665
context [objid ] = 1
676
- readable = True
677
666
components = []
678
667
append = components .append
679
668
level += 1
680
669
for o in object :
681
- orepr , oreadable = self .format (o , context , maxlevels , level )
670
+ orepr = self .format (o , context , maxlevels , level )
682
671
append (orepr )
683
- if not oreadable :
684
- readable = False
685
672
del context [objid ]
686
- return format % ", " .join (components ), readable
673
+ return format % ", " .join (components )
687
674
688
- rep = repr (object )
689
- return rep , bool (rep and not rep .startswith ("<" ))
675
+ return repr (object )
690
676
691
677
692
678
_builtin_scalars = frozenset ({str , bytes , bytearray , float , complex , bool , type (None )})
0 commit comments