##// END OF EJS Templates
Better support compiling cells with separate __future__ environments
Thomas Kluyver -
Show More
@@ -90,7 +90,7 b' class CachingCompiler(codeop.Compile):'
90 90 # Now, we must monkeypatch the linecache directly so that parts of the
91 91 # stdlib that call it outside our control go through our codepath
92 92 # (otherwise we'd lose our tracebacks).
93 linecache.checkcache = self.check_cache
93 linecache.checkcache = check_linecache_ipython
94 94
95 95 def ast_parse(self, source, filename='<unknown>', symbol='exec'):
96 96 """Parse code to an AST with the current compiler flags active.
@@ -134,11 +134,11 b' class CachingCompiler(codeop.Compile):'
134 134 linecache._ipython_cache[name] = entry
135 135 return name
136 136
137 def check_cache(self, *args):
138 """Call linecache.checkcache() safely protecting our cached values.
139 """
140 # First call the orignal checkcache as intended
141 linecache._checkcache_ori(*args)
142 # Then, update back the cache with our data, so that tracebacks related
143 # to our compiled codes can be produced.
144 linecache.cache.update(linecache._ipython_cache)
137 def check_linecache_ipython(*args):
138 """Call linecache.checkcache() safely protecting our cached values.
139 """
140 # First call the orignal checkcache as intended
141 linecache._checkcache_ori(*args)
142 # Then, update back the cache with our data, so that tracebacks related
143 # to our compiled codes can be produced.
144 linecache.cache.update(linecache._ipython_cache)
@@ -41,7 +41,7 b' from IPython.core import ultratb'
41 41 from IPython.core.alias import AliasManager, AliasError
42 42 from IPython.core.autocall import ExitAutocall
43 43 from IPython.core.builtin_trap import BuiltinTrap
44 from IPython.core.compilerop import CachingCompiler
44 from IPython.core.compilerop import CachingCompiler, check_linecache_ipython
45 45 from IPython.core.display_trap import DisplayTrap
46 46 from IPython.core.displayhook import DisplayHook
47 47 from IPython.core.displaypub import DisplayPublisher
@@ -1532,7 +1532,7 b' class InteractiveShell(SingletonConfigurable):'
1532 1532 self.InteractiveTB = ultratb.AutoFormattedTB(mode = 'Plain',
1533 1533 color_scheme='NoColor',
1534 1534 tb_offset = 1,
1535 check_cache=self.compile.check_cache)
1535 check_cache=check_linecache_ipython)
1536 1536
1537 1537 # The instance will store a pointer to the system-wide exception hook,
1538 1538 # so that runtime code (such as magics) can access it. This is because
@@ -2587,12 +2587,7 b' class InteractiveShell(SingletonConfigurable):'
2587 2587 # Our own compiler remembers the __future__ environment. If we want to
2588 2588 # run code with a separate __future__ environment, use the default
2589 2589 # compiler
2590 if shell_futures:
2591 compiler = self.compile
2592 ast_parse = self.compile.ast_parse
2593 else:
2594 compiler = compile
2595 ast_parse = ast.parse
2590 compiler = self.compile if shell_futures else CachingCompiler()
2596 2591
2597 2592 with self.builtin_trap:
2598 2593 prefilter_failed = False
@@ -2622,7 +2617,7 b' class InteractiveShell(SingletonConfigurable):'
2622 2617
2623 2618 with self.display_trap:
2624 2619 try:
2625 code_ast = ast_parse(cell, filename=cell_name)
2620 code_ast = compiler.ast_parse(cell, filename=cell_name)
2626 2621 except IndentationError:
2627 2622 self.showindentationerror()
2628 2623 if store_history:
@@ -67,7 +67,7 b' def test_compiler_check_cache():'
67 67 cp = compilerop.CachingCompiler()
68 68 cp.cache('x=1', 99)
69 69 # Ensure now that after clearing the cache, our entries survive
70 cp.check_cache()
70 linecache.checkcache()
71 71 for k in linecache.cache:
72 72 if k.startswith('<ipython-input-99'):
73 73 break
General Comments 0
You need to be logged in to leave comments. Login now