Title: Using `reprlib.repr` fails for very large numbers · Issue #135487 · python/cpython · GitHub
Open Graph Title: Using `reprlib.repr` fails for very large numbers · Issue #135487 · python/cpython
X Title: Using `reprlib.repr` fails for very large numbers · Issue #135487 · python/cpython
Description: Bug report Bug description: The bug reprlib.Repr.repr_int fails if the integer exceeds the string conversion limit (on line 184) cpython/Lib/reprlib.py Lines 183 to 189 in 6eb6c5d def repr_int(self, x, level): s = builtins.repr(x) # XXX ...
Open Graph Description: Bug report Bug description: The bug reprlib.Repr.repr_int fails if the integer exceeds the string conversion limit (on line 184) cpython/Lib/reprlib.py Lines 183 to 189 in 6eb6c5d def repr_int(self...
X Description: Bug report Bug description: The bug reprlib.Repr.repr_int fails if the integer exceeds the string conversion limit (on line 184) cpython/Lib/reprlib.py Lines 183 to 189 in 6eb6c5d def repr_int(self...
Opengraph URL: https://github.com/python/cpython/issues/135487
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using `reprlib.repr` fails for very large numbers","articleBody":"# Bug report\n\n### Bug description:\n\n### The bug\n\n`reprlib.Repr.repr_int` fails if the integer exceeds the string conversion limit (on line 184)\n\nhttps://github.com/python/cpython/blob/6eb6c5dbfb528bd07d77b60fd71fd05d81d45c41/Lib/reprlib.py#L183-L189\n\nThis impacts other parts of the standard library which use `reprlib.Repr`. A [quick code search](https://github.com/search?q=repo%3Apython%2Fcpython+reprlib+language%3APython+NOT+path%3A%2F%5ELib%5C%2Ftest%5C%2F%2F&type=code&l=Python) reveals that this affects/could affect:\n- `pydoc`\n- `bdb`\n- `idlelib` & IDLE (debugger-related things)\n- `asyncio`\n\nSee https://github.com/python/cpython/issues/135487#issuecomment-2971467201 for detailed rationale for why IMHO this is a bug.\n\n### `pydoc` example\n\nGiven the following code (in a file called `temp11.py`),\n```python\na = 1 \u003c\u003c 19000\n```\nrunning `pydoc` on it like `python -m pydoc '.\\temp11.py'` gives the following error:\n\u003cdetails>\u003csummary>Stack trace\u003c/summary>\n\u003cp>\n\u003cpre>\u003ccode>Traceback (most recent call last):\n File \"\u003cfrozen runpy>\", line 198, in _run_module_as_main\n File \"\u003cfrozen runpy>\", line 88, in _run_code\n File \"C:\\Python313\\Lib\\pydoc.py\", line 2846, in \u003cmodule>\n cli()\n ~~~^^\n File \"C:\\Python313\\Lib\\pydoc.py\", line 2807, in cli\n help.help(arg, is_cli=True)\n ~~~~~~~~~^^^^^^^^^^^^^^^^^^\n File \"C:\\Python313\\Lib\\pydoc.py\", line 2062, in help\n else: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)\n ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"C:\\Python313\\Lib\\pydoc.py\", line 1773, in doc\n pager(render_doc(thing, title, forceload), f'Help on {what!s}')\n ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"C:\\Python313\\Lib\\pydoc.py\", line 1758, in render_doc\n return title % desc + '\\n\\n' + renderer.document(object, name)\n ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^\n File \"C:\\Python313\\Lib\\pydoc.py\", line 543, in document\n if inspect.ismodule(object): return self.docmodule(*args)\n ~~~~~~~~~~~~~~^^^^^^^\n File \"C:\\Python313\\Lib\\pydoc.py\", line 1375, in docmodule\n contents.append(self.docother(value, key, name, maxlen=70))\n ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"C:\\Python313\\Lib\\pydoc.py\", line 1642, in docother\n repr = self.repr(object)\n File \"C:\\Python313\\Lib\\reprlib.py\", line 71, in repr\n return self.repr1(x, self.maxlevel)\n ~~~~~~~~~~^^^^^^^^^^^^^^^^^^\n File \"C:\\Python313\\Lib\\pydoc.py\", line 1234, in repr1\n return getattr(self, methodname)(x, level)\n ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^\n File \"C:\\Python313\\Lib\\reprlib.py\", line 184, in repr_int\n s = builtins.repr(x) # XXX Hope this isn't too slow...\nValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit\n\u003c/pre>\u003c/code>\n\u003c/p>\n\u003c/details>\n\n### Possible fix\nThe underlying issue is that the size of the integer isn't checked before calling builtin `repr`.\nA way to fix this may be to display it as hexadecimal over a certain threshold (then truncate the middle like usual). (IMHO it's not worth it to add a special method to compute the first and last `n` digits of a number without calculating the middle ones)\n\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-135506\n* gh-135886\n* gh-135887\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/MarcellPerger1","@type":"Person","name":"MarcellPerger1"},"datePublished":"2025-06-13T18:42:34Z","url":"https://github.com/python/cpython/issues/135487"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:dc9224ef-c022-121d-e0f4-641a2d823d89 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE70:B1B84:395B131:48DCD93:6B023314 |
| html-safe-nonce | 7abe7e47ff57635e58c4727ad1b4a222368c9c06b1edc14d2a0b9c3bf9a77eca |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTcwOkIxQjg0OjM5NUIxMzE6NDhEQ0Q5Mzo2QjAyMzMxNCIsInZpc2l0b3JfaWQiOiI1OTQzNzI2ODAzNzQxOTc5NDEzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d07928cb6ed402a96fe185fe6c66be4243511e5b15253440195b6ba85c223df5 |
| hovercard-subject-tag | issue:3144447392 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/135487/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bff5506eaab765506223c425732efeff079cd446bb918b755fad02feef29e5fa/python/cpython/issues/135487 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bff5506eaab765506223c425732efeff079cd446bb918b755fad02feef29e5fa/python/cpython/issues/135487 |
| og:image:alt | Bug report Bug description: The bug reprlib.Repr.repr_int fails if the integer exceeds the string conversion limit (on line 184) cpython/Lib/reprlib.py Lines 183 to 189 in 6eb6c5d def repr_int(self... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MarcellPerger1 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width