| 181 | return s |
| 182 | |
| 183 | def repr_int(self, x, level): |
| 184 | try: |
| 185 | s = builtins.repr(x) |
| 186 | except ValueError as exc: |
| 187 | assert 'sys.set_int_max_str_digits()' in str(exc) |
| 188 | # Those imports must be deferred due to Python's build system |
| 189 | # where the reprlib module is imported before the math module. |
| 190 | import math, sys |
| 191 | # Integers with more than sys.get_int_max_str_digits() digits |
| 192 | # are rendered differently as their repr() raises a ValueError. |
| 193 | # See https://github.com/python/cpython/issues/135487. |
| 194 | k = 1 + int(math.log10(abs(x))) |
| 195 | # Note: math.log10(abs(x)) may be overestimated or underestimated, |
| 196 | # but for simplicity, we do not compute the exact number of digits. |
| 197 | max_digits = sys.get_int_max_str_digits() |
| 198 | return (f'<{x.__class__.__name__} instance with roughly {k} ' |
| 199 | f'digits (limit at {max_digits}) at 0x{id(x):x}>') |
| 200 | if len(s) > self.maxlong: |
| 201 | i = max(0, (self.maxlong-3)//2) |
| 202 | j = max(0, self.maxlong-3-i) |
| 203 | s = s[:i] + self.fillvalue + s[len(s)-j:] |
| 204 | return s |
| 205 | |
| 206 | def repr_instance(self, x, level): |
| 207 | try: |