Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "C:\Python313\Lib\pydoc.py", line 2846, in
cli()
~~~^^
File "C:\Python313\Lib\pydoc.py", line 2807, in cli
help.help(arg, is_cli=True)
~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\pydoc.py", line 2062, in help
else: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)
~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\pydoc.py", line 1773, in doc
pager(render_doc(thing, title, forceload), f'Help on {what!s}')
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\pydoc.py", line 1758, in render_doc
return title % desc + '\n\n' + renderer.document(object, name)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "C:\Python313\Lib\pydoc.py", line 543, in document
if inspect.ismodule(object): return self.docmodule(*args)
~~~~~~~~~~~~~~^^^^^^^
File "C:\Python313\Lib\pydoc.py", line 1375, in docmodule
contents.append(self.docother(value, key, name, maxlen=70))
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\pydoc.py", line 1642, in docother
repr = self.repr(object)
File "C:\Python313\Lib\reprlib.py", line 71, in repr
return self.repr1(x, self.maxlevel)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\pydoc.py", line 1234, in repr1
return getattr(self, methodname)(x, level)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "C:\Python313\Lib\reprlib.py", line 184, in repr_int
s = builtins.repr(x) # XXX Hope this isn't too slow...
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
Bug report
Bug description:
The bug
reprlib.Repr.repr_intfails if the integer exceeds the string conversion limit (on line 184)cpython/Lib/reprlib.py
Lines 183 to 189 in 6eb6c5d
This impacts other parts of the standard library which use
reprlib.Repr. A quick code search reveals that this affects/could affect:pydocbdbidlelib& IDLE (debugger-related things)asyncioSee #135487 (comment) for detailed rationale for why IMHO this is a bug.
pydocexampleGiven the following code (in a file called
temp11.py),running
pydocon it likepython -m pydoc '.\temp11.py'gives the following error:Stack trace
Possible fix
The underlying issue is that the size of the integer isn't checked before calling builtin
repr.A 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
ndigits of a number without calculating the middle ones)CPython versions tested on:
3.13
Operating systems tested on:
Windows
Linked PRs
reprlib.Repr.repr_intwhen given very large integers #135506reprlib.Repr.repr_intwhen given very large integers (GH-135506) #135886reprlib.Repr.repr_intwhen given very large integers (GH-135506) #135887