From ff14401a2badf9f4ea4255305fb71ebabf275991 2010-08-12 16:17:10 From: Brian Granger Date: 2010-08-12 16:17:10 Subject: [PATCH] Fixing InteractiveShell creation --- diff --git a/IPython/core/tests/refbug.py b/IPython/core/tests/refbug.py index 6b2ae2b..b049777 100644 --- a/IPython/core/tests/refbug.py +++ b/IPython/core/tests/refbug.py @@ -23,19 +23,25 @@ from IPython.core import ipapi #----------------------------------------------------------------------------- # Globals #----------------------------------------------------------------------------- -ip = ipapi.get() -if not '_refbug_cache' in ip.user_ns: - ip.user_ns['_refbug_cache'] = [] +# This needs to be here because nose and other test runners will import +# this module. Importing this module has potential side effects that we +# want to prevent. +if __name__ == '__main__': + ip = ipapi.get() -aglobal = 'Hello' -def f(): - return aglobal + if not '_refbug_cache' in ip.user_ns: + ip.user_ns['_refbug_cache'] = [] -cache = ip.user_ns['_refbug_cache'] -cache.append(f) -def call_f(): - for func in cache: - print 'lowercased:',func().lower() + aglobal = 'Hello' + def f(): + return aglobal + + cache = ip.user_ns['_refbug_cache'] + cache.append(f) + + def call_f(): + for func in cache: + print 'lowercased:',func().lower() diff --git a/docs/sphinxext/ipython_directive.py b/docs/sphinxext/ipython_directive.py index b71b3d3..cc914ee 100644 --- a/docs/sphinxext/ipython_directive.py +++ b/docs/sphinxext/ipython_directive.py @@ -220,7 +220,7 @@ class EmbeddedSphinxShell(object): config.InteractiveShell.colors = 'NoColor' # Create and initialize ipython, but don't start its mainloop - IP = InteractiveShell(parent=None, config=config) + IP = InteractiveShell.instance(config=config) # Store a few parts of IPython we'll need. self.IP = IP