1414# The cache. Maps filenames to either a thunk which will provide source code,
1515# or a tuple (size, mtime, lines, fullname) once loaded.
1616cache = {}
17+ _interactive_cache = {}
1718
1819
1920def clearcache ():
@@ -35,10 +36,11 @@ def getlines(filename, module_globals=None):
3536 """Get the lines for a Python source file from the cache.
3637 Update the cache if it doesn't contain an entry for this file already."""
3738
38- if filename in cache :
39- entry = cache [filename ]
40- if len (entry ) != 1 :
41- return cache [filename ][2 ]
39+ for the_cache in (cache , _interactive_cache ):
40+ if filename in the_cache :
41+ entry = the_cache [filename ]
42+ if len (entry ) != 1 :
43+ return the_cache [filename ][2 ]
4244
4345 try :
4446 return updatecache (filename , module_globals )
@@ -159,11 +161,12 @@ def lazycache(filename, module_globals):
159161 get_source method must be found, the filename must be a cacheable
160162 filename, and the filename must not be already cached.
161163 """
162- if filename in cache :
163- if len (cache [filename ]) == 1 :
164- return True
165- else :
166- return False
164+ for the_cache in (cache , _interactive_cache ):
165+ if filename in the_cache :
166+ if len (the_cache [filename ]) == 1 :
167+ return True
168+ else :
169+ return False
167170 if not filename or (filename .startswith ('<' ) and filename .endswith ('>' )):
168171 return False
169172 # Try for a __loader__, if available
@@ -183,8 +186,8 @@ def get_lines(name=name, *args, **kwargs):
183186 return False
184187
185188
186- def _register_code (code , string , name ):
187- cache [ code ] = (
189+ def _register_code (code , filename , string , name ):
190+ _interactive_cache [ filename ] = (
188191 len (string ),
189192 None ,
190193 [line + '\n ' for line in string .splitlines ()],
0 commit comments