@@ -2508,7 +2508,6 @@ def complete_shell(self, text, line, begidx, endidx):
25082508 index_dict = {1 : self .shell_cmd_complete }
25092509 return self .index_based_complete (text , line , begidx , endidx , index_dict , self .path_complete )
25102510
2511- # noinspection PyBroadException
25122511 def do_py (self , arg ):
25132512 """
25142513 Invoke python command, shell, or script
@@ -2525,6 +2524,7 @@ def do_py(self, arg):
25252524 return
25262525 self ._in_py = True
25272526
2527+ # noinspection PyBroadException
25282528 try :
25292529 arg = arg .strip ()
25302530
@@ -2581,12 +2581,11 @@ def quit():
25812581 for i in range (1 , readline .get_current_history_length () + 1 ):
25822582 saved_cmd2_history .append (readline .get_history_item (i ))
25832583
2584- # Keep a list of commands run in the Python console
2585- # noinspection PyAttributeOutsideInit
2586- self .py_history = getattr (self , 'py_history' , [])
2584+ readline .clear_history ()
25872585
25882586 # Restore py's history
2589- readline .clear_history ()
2587+ # noinspection PyAttributeOutsideInit
2588+ self .py_history = getattr (self , 'py_history' , [])
25902589 for item in self .py_history :
25912590 readline .add_history (item )
25922591
@@ -2639,11 +2638,14 @@ def quit():
26392638
26402639 if rl_type != RlType .NONE :
26412640 # Save py's history
2641+ # noinspection PyAttributeOutsideInit
2642+ self .py_history = []
26422643 for i in range (1 , readline .get_current_history_length () + 1 ):
26432644 self .py_history .append (readline .get_history_item (i ))
26442645
2645- # Restore cmd2's history
26462646 readline .clear_history ()
2647+
2648+ # Restore cmd2's history
26472649 for item in saved_cmd2_history :
26482650 readline .add_history (item )
26492651
0 commit comments