Skip to content

Commit b82188d

Browse files
bpo-26806: IDLE should run without docstrings (GH-14657) (GH-14677)
After fcf1d00, IDLE startup failed with python compiled without docstrings. (cherry picked from commit 6aeb2fe) Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent 68bd9c5 commit b82188d

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Lib/idlelib/idle_test/test_run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ def test_default_recursion_limit_preserved(self):
292292
new_reclimit = sys.getrecursionlimit()
293293
self.assertEqual(new_reclimit, orig_reclimit)
294294

295+
def test_fixdoc(self):
296+
def func(): "docstring"
297+
run.fixdoc(func, "more")
298+
self.assertEqual(func.__doc__, "docstring\n\nmore")
299+
func.__doc__ = None
300+
run.fixdoc(func, "more")
301+
self.assertEqual(func.__doc__, "more")
302+
295303

296304
if __name__ == '__main__':
297305
unittest.main(verbosity=2)

Lib/idlelib/run.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,12 @@ def fix_scaling(root):
307307
font['size'] = round(-0.75*size)
308308

309309

310+
def fixdoc(fun, text):
311+
tem = (fun.__doc__ + '\n\n') if fun.__doc__ is not None else ''
312+
fun.__doc__ = tem + textwrap.fill(textwrap.dedent(text))
313+
310314
RECURSIONLIMIT_DELTA = 30
315+
311316
def install_recursionlimit_wrappers():
312317
"""Install wrappers to always add 30 to the recursion limit."""
313318
# see: bpo-26806
@@ -329,19 +334,17 @@ def setrecursionlimit(*args, **kwargs):
329334

330335
return setrecursionlimit.__wrapped__(limit + RECURSIONLIMIT_DELTA)
331336

332-
setrecursionlimit.__doc__ += "\n\n" + textwrap.fill(textwrap.dedent(f"""\
333-
This IDLE wrapper adds {RECURSIONLIMIT_DELTA} to prevent possible
334-
uninterruptible loops.
335-
""").strip())
337+
fixdoc(setrecursionlimit, f"""\
338+
This IDLE wrapper adds {RECURSIONLIMIT_DELTA} to prevent possible
339+
uninterruptible loops.""")
336340

337341
@functools.wraps(sys.getrecursionlimit)
338342
def getrecursionlimit():
339343
return getrecursionlimit.__wrapped__() - RECURSIONLIMIT_DELTA
340344

341-
getrecursionlimit.__doc__ += "\n\n" + textwrap.fill(textwrap.dedent(f"""\
342-
This IDLE wrapper subtracts {RECURSIONLIMIT_DELTA} to compensate for
343-
the {RECURSIONLIMIT_DELTA} IDLE adds when setting the limit.
344-
""").strip())
345+
fixdoc(getrecursionlimit, f"""\
346+
This IDLE wrapper subtracts {RECURSIONLIMIT_DELTA} to compensate
347+
for the {RECURSIONLIMIT_DELTA} IDLE adds when setting the limit.""")
345348

346349
# add the delta to the default recursion limit, to compensate
347350
sys.setrecursionlimit(sys.getrecursionlimit() + RECURSIONLIMIT_DELTA)

0 commit comments

Comments
 (0)