diff --git a/IPython/iplib.py b/IPython/iplib.py index ef2f044..b9d758e 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -1487,7 +1487,7 @@ class InteractiveShell(object,Magic): return True return ask_yes_no(prompt,default) - def cache_main_mod(self,mod): + def cache_main_mod(self,mod,fname=None): """Cache a main module. When scripts are executed via %run, we must keep a reference to their @@ -1515,7 +1515,10 @@ class InteractiveShell(object,Magic): In [12]: IPython.__file__ in _ip.IP._user_main_modules Out[12]: True """ - self._user_main_modules[os.path.abspath(mod.__file__) ] = mod + if fname is None: + fname = mod.__file__ + #print >> sys.stderr, 'CFNAME :', os.path.abspath(fname) # dbg + self._user_main_modules[os.path.abspath(fname)] = mod def clear_main_mod_cache(self): """Clear the cache of main modules. diff --git a/IPython/tests/test_magic.py b/IPython/tests/test_magic.py index 4878710..cde72f4 100644 --- a/IPython/tests/test_magic.py +++ b/IPython/tests/test_magic.py @@ -131,3 +131,19 @@ def test_fail_dec2(*a,**k): def test_fail_dec3(*a,**k): yield nt.assert_true, False + +def doctest_refbug(): + """Very nasty problem with references held by multiple runs of a script. + See: https://bugs.launchpad.net/ipython/+bug/269966 + + In [2]: run refbug + + In [3]: call_f() + lowercased: hello + + In [4]: run refbug + + In [5]: call_f() + lowercased: hello + lowercased: hello + """