@@ -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
6870class PyShellEditorWindow (EditorWindow ):
0 commit comments