@@ -556,17 +556,29 @@ def _safe_repr(self, object, context, maxlevels, level):
556556 return "{%s}" % ", " .join (components ), readable , recursive
557557
558558 if (issubclass (typ , list ) and r is list .__repr__ ) or \
559- (issubclass (typ , tuple ) and r is tuple .__repr__ ):
559+ (issubclass (typ , tuple ) and r is tuple .__repr__ ) or \
560+ (issubclass (typ , set ) and r is set .__repr__ ) or \
561+ (issubclass (typ , frozenset ) and r is frozenset .__repr__ ):
560562 if issubclass (typ , list ):
561563 if not object :
562564 return "[]" , True , False
563565 format = "[%s]"
564- elif len (object ) == 1 :
565- format = "(%s,)"
566+ elif issubclass (typ , tuple ):
567+ if len (object ) == 1 :
568+ format = "(%s,)"
569+ else :
570+ if not object :
571+ return "()" , True , False
572+ format = "(%s)"
566573 else :
567574 if not object :
568- return "()" , True , False
569- format = "(%s)"
575+ return repr (object ), True , False
576+ if typ is set :
577+ format = "{%s}"
578+ else :
579+ format = typ .__name__ + "({%s})"
580+ object = sorted (object , key = _safe_key )
581+
570582 objid = id (object )
571583 if maxlevels and level >= maxlevels :
572584 return format % "..." , False , objid in context
@@ -589,37 +601,6 @@ def _safe_repr(self, object, context, maxlevels, level):
589601 del context [objid ]
590602 return format % ", " .join (components ), readable , recursive
591603
592- if (issubclass (typ , set ) and r is set .__repr__ ) or \
593- (issubclass (typ , frozenset ) and r is frozenset .__repr__ ):
594- if not object :
595- return repr (object ), True , False
596- if typ is set :
597- format = "{%s}"
598- else :
599- format = typ .__name__ + "({%s})"
600- objid = id (object )
601- if maxlevels and level >= maxlevels :
602- return "{...}" , False , objid in context
603- if objid in context :
604- return _recursion (object ), False , True
605- context [objid ] = 1
606- readable = True
607- recursive = False
608- components = []
609- append = components .append
610- level += 1
611- items = sorted (object , key = _safe_key )
612- for item in items :
613- orepr , oreadable , orecur = self .format (
614- item , context , maxlevels , level )
615- append ("%s" % orepr )
616- if not oreadable :
617- readable = False
618- if orecur :
619- recursive = True
620- del context [objid ]
621- return format % ", " .join (components ), readable , recursive
622-
623604 rep = repr (object )
624605 return rep , (rep and not rep .startswith ('<' )), False
625606
0 commit comments