| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -489,24 +489,8 @@ def _pprint_user_string(self, object, stream, indent, allowance, context, level) | |||
| 489 | 489 | ||
| 490 | 490 | def _safe_repr(object, context, maxlevels, level): | |
| 491 | 491 | 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 | ||
| 510 | 494 | ||
| 511 | 495 | r = getattr(typ, "__repr__", None) | |
| 512 | 496 | if issubclass(typ, dict) and r is dict.__repr__: | |
@@ -571,6 +555,8 @@ def _safe_repr(object, context, maxlevels, level): | |||
| 571 | 555 | rep = repr(object) | |
| 572 | 556 | return rep, (rep and not rep.startswith('<')), False | |
| 573 | 557 | ||
| 558 | + _builtin_scalars = frozenset({str, bytes, bytearray, int, float, complex, | ||
| 559 | + bool, type(None)}) | ||
| 574 | 560 | ||
| 575 | 561 | def _recursion(object): | |
| 576 | 562 | return ("<Recursion on %s with id=%s>" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,8 @@ Core and Builtins | |||
| 47 | 47 | Library | |
| 48 | 48 | ------- | |
| 49 | 49 | ||
| 50 | + - Issue #18682: Optimized pprint functions for builtin scalar types. | ||
| 51 | + | ||
| 50 | 52 | - Issue #22027: smtplib now supports RFC 6531 (SMTPUTF8). | |
| 51 | 53 | ||
| 52 | 54 | - Issue #23488: Random generator objects now consume 2x less memory on 64-bit. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments