@@ -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 ._recursive = True
118
117
self ._readable = False
119
118
return
120
119
@@ -487,21 +486,16 @@ def _format_items(
487
486
write ("\n " + " " * indent )
488
487
489
488
def _repr (self , object : Any , context : Dict [int , int ], level : int ) -> str :
490
- repr , readable , recursive = self .format (
491
- object , context .copy (), self ._depth , level
492
- )
489
+ repr , readable = self .format (object , context .copy (), self ._depth , level )
493
490
if not readable :
494
491
self ._readable = False
495
- if recursive :
496
- self ._recursive = True
497
492
return repr
498
493
499
494
def format (
500
495
self , object : Any , context : Dict [int , int ], maxlevels : Optional [int ], level : int
501
- ) -> Tuple [str , bool , bool ]:
496
+ ) -> Tuple [str , bool ]:
502
497
"""Format object for a specific context, returning a string
503
- and flags indicating whether the representation is 'readable'
504
- and whether the object represents a recursive construct.
498
+ and a flag indicating whether the representation is 'readable'.
505
499
"""
506
500
return self ._safe_repr (object , context , maxlevels , level )
507
501
@@ -621,31 +615,30 @@ def _pprint_user_string(
621
615
622
616
def _safe_repr (
623
617
self , object : Any , context : Dict [int , int ], maxlevels : Optional [int ], level : int
624
- ) -> Tuple [str , bool , bool ]:
625
- # Return triple (repr_string, isreadable, isrecursive ).
618
+ ) -> Tuple [str , bool ]:
619
+ # Return pair (repr_string, isreadable).
626
620
typ = type (object )
627
621
if typ in _builtin_scalars :
628
- return repr (object ), True , False
622
+ return repr (object ), True
629
623
630
624
r = getattr (typ , "__repr__" , None )
631
625
632
626
if issubclass (typ , int ) and r is int .__repr__ :
633
627
if self ._underscore_numbers :
634
- return f"{ object :_d} " , True , False
628
+ return f"{ object :_d} " , True
635
629
else :
636
- return repr (object ), True , False
630
+ return repr (object ), True
637
631
638
632
if issubclass (typ , dict ) and r is dict .__repr__ :
639
633
if not object :
640
- return "{}" , True , False
634
+ return "{}" , True
641
635
objid = id (object )
642
636
if maxlevels and level >= maxlevels :
643
- return "{...}" , False , objid in context
637
+ return "{...}" , False
644
638
if objid in context :
645
- return _recursion (object ), False , True
639
+ return _recursion (object ), False
646
640
context [objid ] = 1
647
641
readable = True
648
- recursive = False
649
642
components : List [str ] = []
650
643
append = components .append
651
644
level += 1
@@ -654,51 +647,46 @@ def _safe_repr(
654
647
else :
655
648
items = object .items ()
656
649
for k , v in items :
657
- krepr , kreadable , krecur = self .format (k , context , maxlevels , level )
658
- vrepr , vreadable , vrecur = self .format (v , context , maxlevels , level )
650
+ krepr , kreadable = self .format (k , context , maxlevels , level )
651
+ vrepr , vreadable = self .format (v , context , maxlevels , level )
659
652
append (f"{ krepr } : { vrepr } " )
660
653
readable = readable and kreadable and vreadable
661
- if krecur or vrecur :
662
- recursive = True
663
654
del context [objid ]
664
- return "{%s}" % ", " .join (components ), readable , recursive
655
+ return "{%s}" % ", " .join (components ), readable
665
656
666
657
if (issubclass (typ , list ) and r is list .__repr__ ) or (
667
658
issubclass (typ , tuple ) and r is tuple .__repr__
668
659
):
669
660
if issubclass (typ , list ):
670
661
if not object :
671
- return "[]" , True , False
662
+ return "[]" , True
672
663
format = "[%s]"
673
664
elif len (object ) == 1 :
674
665
format = "(%s,)"
675
666
else :
676
667
if not object :
677
- return "()" , True , False
668
+ return "()" , True
678
669
format = "(%s)"
679
670
objid = id (object )
680
671
if maxlevels and level >= maxlevels :
681
- return format % "..." , False , objid in context
672
+ return format % "..." , False
682
673
if objid in context :
683
- return _recursion (object ), False , True
674
+ return _recursion (object ), False
684
675
context [objid ] = 1
685
676
readable = True
686
- recursive = False
687
677
components = []
688
678
append = components .append
689
679
level += 1
690
680
for o in object :
691
- orepr , oreadable , orecur = self .format (o , context , maxlevels , level )
681
+ orepr , oreadable = self .format (o , context , maxlevels , level )
692
682
append (orepr )
693
683
if not oreadable :
694
684
readable = False
695
- if orecur :
696
- recursive = True
697
685
del context [objid ]
698
- return format % ", " .join (components ), readable , recursive
686
+ return format % ", " .join (components ), readable
699
687
700
688
rep = repr (object )
701
- return rep , bool (rep and not rep .startswith ("<" )), False
689
+ return rep , bool (rep and not rep .startswith ("<" ))
702
690
703
691
704
692
_builtin_scalars = frozenset ({str , bytes , bytearray , float , complex , bool , type (None )})
0 commit comments