From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 9 Jul 2019 18:59:19 +0000 (-0700) Subject: bpo-26806: IDLE should run without docstrings (GH-14657) (GH-14677) X-Git-Tag: v3.8.0b3~73 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b82188d9bad1774624cb1788dbdec2f0d7d65688;p=thirdparty%2FPython%2Fcpython.git 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 6aeb2fe606408aae14c246470794f1303b3be812) Co-authored-by: Terry Jan Reedy --- diff --git a/Lib/idlelib/idle_test/test_run.py b/Lib/idlelib/idle_test/test_run.py index d0f1e9207bb1..cad0b4d98f8e 100644 --- a/Lib/idlelib/idle_test/test_run.py +++ b/Lib/idlelib/idle_test/test_run.py @@ -292,6 +292,14 @@ class TestSysRecursionLimitWrappers(unittest.TestCase): new_reclimit = sys.getrecursionlimit() self.assertEqual(new_reclimit, orig_reclimit) + def test_fixdoc(self): + def func(): "docstring" + run.fixdoc(func, "more") + self.assertEqual(func.__doc__, "docstring\n\nmore") + func.__doc__ = None + run.fixdoc(func, "more") + self.assertEqual(func.__doc__, "more") + if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index c6ed76b23a2d..41e0ded44029 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -307,7 +307,12 @@ def fix_scaling(root): font['size'] = round(-0.75*size) +def fixdoc(fun, text): + tem = (fun.__doc__ + '\n\n') if fun.__doc__ is not None else '' + fun.__doc__ = tem + textwrap.fill(textwrap.dedent(text)) + RECURSIONLIMIT_DELTA = 30 + def install_recursionlimit_wrappers(): """Install wrappers to always add 30 to the recursion limit.""" # see: bpo-26806 @@ -329,19 +334,17 @@ def install_recursionlimit_wrappers(): return setrecursionlimit.__wrapped__(limit + RECURSIONLIMIT_DELTA) - setrecursionlimit.__doc__ += "\n\n" + textwrap.fill(textwrap.dedent(f"""\ - This IDLE wrapper adds {RECURSIONLIMIT_DELTA} to prevent possible - uninterruptible loops. - """).strip()) + fixdoc(setrecursionlimit, f"""\ + This IDLE wrapper adds {RECURSIONLIMIT_DELTA} to prevent possible + uninterruptible loops.""") @functools.wraps(sys.getrecursionlimit) def getrecursionlimit(): return getrecursionlimit.__wrapped__() - RECURSIONLIMIT_DELTA - getrecursionlimit.__doc__ += "\n\n" + textwrap.fill(textwrap.dedent(f"""\ - This IDLE wrapper subtracts {RECURSIONLIMIT_DELTA} to compensate for - the {RECURSIONLIMIT_DELTA} IDLE adds when setting the limit. - """).strip()) + fixdoc(getrecursionlimit, f"""\ + This IDLE wrapper subtracts {RECURSIONLIMIT_DELTA} to compensate + for the {RECURSIONLIMIT_DELTA} IDLE adds when setting the limit.""") # add the delta to the default recursion limit, to compensate sys.setrecursionlimit(sys.getrecursionlimit() + RECURSIONLIMIT_DELTA)