From c10daec2383e55fc66c3038e47eff8f98f6a8a12 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Tue, 9 Jul 2019 02:04:08 -0400 Subject: [PATCH 1/2] bpo-26806: IDLE should still run without docs Fix regression introduced by fcf1d00. --- Lib/idlelib/run.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index c6ed76b23a2d1b..a6bc7ed04bd86e 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -328,20 +328,23 @@ def setrecursionlimit(*args, **kwargs): "recursion limit must be greater or equal than 1") 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()) + if setrecursionlimit.__doc__ is not None: + setrecursionlimit.__doc__ += ( + "\n\n" + textwrap.fill(textwrap.dedent(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()) + if getrecursionlimit.__doc__ is not None: + 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. + """))) # add the delta to the default recursion limit, to compensate sys.setrecursionlimit(sys.getrecursionlimit() + RECURSIONLIMIT_DELTA) From 259c9b13c0a59f19d2e19d321c94e7f653a2dc75 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Tue, 9 Jul 2019 05:02:50 -0400 Subject: [PATCH 2/2] Change solution and add test. --- Lib/idlelib/idle_test/test_run.py | 8 ++++++++ Lib/idlelib/run.py | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Lib/idlelib/idle_test/test_run.py b/Lib/idlelib/idle_test/test_run.py index d0f1e9207bb17c..cad0b4d98f8e0d 100644 --- a/Lib/idlelib/idle_test/test_run.py +++ b/Lib/idlelib/idle_test/test_run.py @@ -292,6 +292,14 @@ def test_default_recursion_limit_preserved(self): 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 a6bc7ed04bd86e..41e0ded4402937 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 @@ -328,23 +333,18 @@ def setrecursionlimit(*args, **kwargs): "recursion limit must be greater or equal than 1") return setrecursionlimit.__wrapped__(limit + RECURSIONLIMIT_DELTA) - if setrecursionlimit.__doc__ is not None: - setrecursionlimit.__doc__ += ( - "\n\n" + textwrap.fill(textwrap.dedent(f"""\ + + fixdoc(setrecursionlimit, f"""\ This IDLE wrapper adds {RECURSIONLIMIT_DELTA} to prevent possible - uninterruptible loops. - """))) + uninterruptible loops.""") @functools.wraps(sys.getrecursionlimit) def getrecursionlimit(): return getrecursionlimit.__wrapped__() - RECURSIONLIMIT_DELTA - if getrecursionlimit.__doc__ is not None: - getrecursionlimit.__doc__ += ( - "\n\n" + textwrap.fill(textwrap.dedent(f"""\ + fixdoc(getrecursionlimit, f"""\ This IDLE wrapper subtracts {RECURSIONLIMIT_DELTA} to compensate - for the {RECURSIONLIMIT_DELTA} IDLE adds when setting the limit. - """))) + 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)