Skip to content

bpo-26806: IDLE should run without docstrings #14657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/idlelib/idle_test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 11 additions & 8 deletions Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -329,19 +334,17 @@ def setrecursionlimit(*args, **kwargs):

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)
Expand Down