@@ -64,9 +64,6 @@ def __init__(
6464 indent : int = 4 ,
6565 width : int = 80 ,
6666 depth : Optional [int ] = None ,
67- * ,
68- sort_dicts : bool = True ,
69- underscore_numbers : bool = False ,
7067 ) -> None :
7168 """Handle pretty printing operations onto a stream using a set of
7269 configured parameters.
@@ -80,12 +77,7 @@ def __init__(
8077 depth
8178 The maximum depth to print out nested structures.
8279
83- sort_dicts
84- If true, dict keys are sorted.
85-
8680 """
87- indent = int (indent )
88- width = int (width )
8981 if indent < 0 :
9082 raise ValueError ("indent must be >= 0" )
9183 if depth is not None and depth <= 0 :
@@ -95,8 +87,6 @@ def __init__(
9587 self ._depth = depth
9688 self ._indent_per_level = indent
9789 self ._width = width
98- self ._sort_dicts = sort_dicts
99- self ._underscore_numbers = underscore_numbers
10090
10191 def pformat (self , object : Any ) -> str :
10292 sio = _StringIO ()
@@ -174,10 +164,7 @@ def _pprint_dict(
174164 ) -> None :
175165 write = stream .write
176166 write ("{" )
177- if self ._sort_dicts :
178- items = sorted (object .items (), key = _safe_tuple )
179- else :
180- items = object .items ()
167+ items = sorted (object .items (), key = _safe_tuple )
181168 self ._format_dict_items (items , stream , indent , allowance , context , level )
182169 write ("}" )
183170
@@ -486,12 +473,7 @@ def _format_items(
486473 write ("\n " + " " * indent )
487474
488475 def _repr (self , object : Any , context : Set [int ], level : int ) -> str :
489- return self .format (object , context .copy (), self ._depth , level )
490-
491- def format (
492- self , object : Any , context : Set [int ], maxlevels : Optional [int ], level : int
493- ) -> str :
494- return self ._safe_repr (object , context , maxlevels , level )
476+ return self ._safe_repr (object , context .copy (), self ._depth , level )
495477
496478 def _pprint_default_dict (
497479 self ,
@@ -616,12 +598,6 @@ def _safe_repr(
616598
617599 r = getattr (typ , "__repr__" , None )
618600
619- if issubclass (typ , int ) and r is int .__repr__ :
620- if self ._underscore_numbers :
621- return f"{ object :_d} "
622- else :
623- return repr (object )
624-
625601 if issubclass (typ , dict ) and r is dict .__repr__ :
626602 if not object :
627603 return "{}"
@@ -634,13 +610,9 @@ def _safe_repr(
634610 components : List [str ] = []
635611 append = components .append
636612 level += 1
637- if self ._sort_dicts :
638- items = sorted (object .items (), key = _safe_tuple )
639- else :
640- items = object .items ()
641- for k , v in items :
642- krepr = self .format (k , context , maxlevels , level )
643- vrepr = self .format (v , context , maxlevels , level )
613+ for k , v in sorted (object .items (), key = _safe_tuple ):
614+ krepr = self ._safe_repr (k , context , maxlevels , level )
615+ vrepr = self ._safe_repr (v , context , maxlevels , level )
644616 append (f"{ krepr } : { vrepr } " )
645617 context .remove (objid )
646618 return "{%s}" % ", " .join (components )
@@ -668,15 +640,17 @@ def _safe_repr(
668640 append = components .append
669641 level += 1
670642 for o in object :
671- orepr = self .format (o , context , maxlevels , level )
643+ orepr = self ._safe_repr (o , context , maxlevels , level )
672644 append (orepr )
673645 context .remove (objid )
674646 return format % ", " .join (components )
675647
676648 return repr (object )
677649
678650
679- _builtin_scalars = frozenset ({str , bytes , bytearray , float , complex , bool , type (None )})
651+ _builtin_scalars = frozenset (
652+ {str , bytes , bytearray , float , complex , bool , type (None ), int }
653+ )
680654
681655
682656def _recursion (object : Any ) -> str :
0 commit comments