Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8188559

Browse files
committed
Correct an error introduced at Rev 1.30. The keyword arg is necessary
to freeze the value of orig_checkcache. Otherwise infinite recursion.
1 parent 24884f7 commit 8188559

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Lib/idlelib/PyShell.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ def idle_showwarning(message, category, filename, lineno):
4545
file.write(warnings.formatwarning(message, category, filename, lineno))
4646
warnings.showwarning = idle_showwarning
4747

48-
def linecache_checkcache():
48+
def extended_linecache_checkcache(orig_checkcache=linecache.checkcache):
4949
"""Extend linecache.checkcache to preserve the <pyshell#...> entries
5050
51-
Rather than repeating the linecache code, patch it by saving the pyshell#
52-
entries, call linecache.checkcache(), and then restore the saved
53-
entries.
51+
Rather than repeating the linecache code, patch it to save the pyshell#
52+
entries, call the original linecache.checkcache(), and then restore the
53+
saved entries. Assigning the orig_checkcache keyword arg freezes its value
54+
at definition time to the (original) method linecache.checkcache(), i.e.
55+
makes orig_checkcache lexical.
5456
5557
"""
56-
orig_checkcache=linecache.checkcache
5758
cache = linecache.cache
5859
save = {}
5960
for filename in cache.keys():
@@ -62,7 +63,8 @@ def linecache_checkcache():
6263
orig_checkcache()
6364
cache.update(save)
6465

65-
linecache.checkcache = linecache_checkcache
66+
# Patch linecache.checkcache():
67+
linecache.checkcache = extended_linecache_checkcache
6668

6769

6870
class PyShellEditorWindow(EditorWindow):

0 commit comments

Comments
 (0)