@@ -489,24 +489,8 @@ def _pprint_user_string(self, object, stream, indent, allowance, context, level)
489489
490490def _safe_repr (object , context , maxlevels , level ):
491491 typ = type (object )
492- if typ is str :
493- if 'locale' not in _sys .modules :
494- return repr (object ), True , False
495- if "'" in object and '"' not in object :
496- closure = '"'
497- quotes = {'"' : '\\ "' }
498- else :
499- closure = "'"
500- quotes = {"'" : "\\ '" }
501- qget = quotes .get
502- sio = _StringIO ()
503- write = sio .write
504- for char in object :
505- if char .isalpha ():
506- write (char )
507- else :
508- write (qget (char , repr (char )[1 :- 1 ]))
509- return ("%s%s%s" % (closure , sio .getvalue (), closure )), True , False
492+ if typ in _builtin_scalars :
493+ return repr (object ), True , False
510494
511495 r = getattr (typ , "__repr__" , None )
512496 if issubclass (typ , dict ) and r is dict .__repr__ :
@@ -571,6 +555,8 @@ def _safe_repr(object, context, maxlevels, level):
571555 rep = repr (object )
572556 return rep , (rep and not rep .startswith ('<' )), False
573557
558+ _builtin_scalars = frozenset ({str , bytes , bytearray , int , float , complex ,
559+ bool , type (None )})
574560
575561def _recursion (object ):
576562 return ("<Recursion on %s with id=%s>"
0 commit comments