Skip to content

Commit 3d5945f

Browse files
gh-150285: Fix overflow in too long lines for class data in pydoc
Use all available space (80 columns) for formatting reprs of module and class data, but ensure that they do not overflow.
1 parent 0066fd7 commit 3d5945f

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/pydoc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
13551355
if data:
13561356
contents = []
13571357
for key, value in data:
1358-
contents.append(self.docother(value, key, name, maxlen=70))
1358+
contents.append(self.docother(value, key, name, maxlen=76))
13591359
result = result + self.section('DATA', '\n'.join(contents))
13601360

13611361
if version := self._get_version(object):
@@ -1478,7 +1478,7 @@ def spilldata(msg, attrs, predicate):
14781478
obj = getattr(object, name)
14791479
except AttributeError:
14801480
obj = homecls.__dict__[name]
1481-
push(self.docother(obj, name, mod, maxlen=70, doc=doc) +
1481+
push(self.docother(obj, name, mod, maxlen=72, doc=doc) +
14821482
'\n')
14831483
return attrs
14841484

@@ -1629,7 +1629,7 @@ def docother(self, object, name=None, mod=None, parent=None, *ignored,
16291629
if maxlen:
16301630
line = (name and name + ' = ' or '') + repr
16311631
chop = maxlen - len(line)
1632-
if chop < 0: repr = repr[:chop] + '...'
1632+
if chop < 0: repr = repr[:chop-3] + '...'
16331633
line = (name and self.bold(name) + ' = ' or '') + repr
16341634
if not doc:
16351635
doc = getdoc(object)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`pydoc` now uses all available space (80 columns) for formatting reprs
2+
of module and class data, but ensure that they do not overflow.

0 commit comments

Comments
 (0)