From e271838293f5954c1f74a0d37eebc1d24d6ccaaf 2012-01-21 08:06:59 From: Paul Ivanov Date: 2012-01-21 08:06:59 Subject: [PATCH] %clear magic now fully restored Previously, the %clear completions did not advertise the 'array' argument option, which is now fixed. --- diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 2834a69..09344f8 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -205,14 +205,14 @@ def test_clear(): nt.assert_true('dead' in [_ip.user_ns[x] for x in '_','__','___']) _ip.magic('clear out') nt.assert_false('dead' in [_ip.user_ns[x] for x in '_','__','___']) - nt.assert_true(len(_ip.user_ns['Out']) ==0) + nt.assert_true(len(_ip.user_ns['Out']) == 0) # test '%clear in' _ip.run_cell("parrot", store_history=True) nt.assert_true('parrot' in [_ip.user_ns[x] for x in '_i','_ii','_iii']) _ip.magic('%clear in') nt.assert_false('parrot' in [_ip.user_ns[x] for x in '_i','_ii','_iii']) - nt.assert_true(len(_ip.user_ns['In'] ==0)) + nt.assert_true(len(_ip.user_ns['In']) == 0) # test '%clear dhist' _ip.run_cell("tmp = [d for d in _dh]") # copy before clearing diff --git a/IPython/extensions/clearcmd.py b/IPython/extensions/clearcmd.py index c61f1f2..d6ce730 100644 --- a/IPython/extensions/clearcmd.py +++ b/IPython/extensions/clearcmd.py @@ -44,14 +44,11 @@ def clear_f(self,arg): print "Flushing input history" pc = self.displayhook.prompt_count + 1 for n in range(1, pc): - key = '_i'+`n` + key = '_i'+repr(n) user_ns.pop(key,None) - try: - del user_ns[key] - except: pass - # must be done in-place - self.history_manager.input_hist_parsed[:] = ['\n'] * pc - self.history_manager.input_hist_raw[:] = ['\n'] * pc + user_ns.update(dict(_i=u'',_ii=u'',_iii=u'')) + del self.history_manager.input_hist_parsed[:] + del self.history_manager.input_hist_raw[:] elif target == 'array': # Support cleaning up numpy arrays @@ -62,7 +59,7 @@ def clear_f(self,arg): for x,val in user_ns.items(): if isinstance(val,ndarray): del user_ns[x] - except AttributeError: + except ImportError: print "Clear array only works if Numpy is available." elif target == 'shadow_compress': @@ -83,4 +80,4 @@ def clear_f(self,arg): # Activate the extension ip.define_magic("clear",clear_f) from IPython.core.completerlib import quick_completer -quick_completer( '%clear','in out shadow_nuke shadow_compress dhist') +quick_completer('%clear','in out array shadow_nuke shadow_compress dhist')