Skip to content

Commit

Permalink
Make ip.reset() work the same in interactive or non-interactive code.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Apr 9, 2011
1 parent 5744340 commit 527f067
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions IPython/core/interactiveshell.py
Expand Up @@ -1050,7 +1050,7 @@ def reset(self, new_session=True):
self.displayhook.flush()

# Reset counter used to index all histories
self.execution_count = 0
self.execution_count = 1

# Restore the user namespaces to minimal usability
for ns in self.ns_refs_table:
Expand All @@ -1076,6 +1076,10 @@ def reset(self, new_session=True):
# Flush the private list of module references kept for script
# execution protection
self.clear_main_mod_cache()

# If this is run from interactive code, we don't want run_cell to bump
# up the execution_count
self.increment_exec_count = False

def reset_selective(self, regex=None):
"""Clear selective variables from internal namespaces based on a
Expand Down Expand Up @@ -2121,6 +2125,7 @@ def run_cell(self, cell, store_history=True):
should be set to False.
"""
raw_cell = cell
self.increment_exec_count = True
with self.builtin_trap:
cell = self.prefilter_manager.prefilter_lines(cell)

Expand All @@ -2139,7 +2144,8 @@ def run_cell(self, cell, store_history=True):
except (OverflowError, SyntaxError, ValueError, TypeError, MemoryError):
# Case 1
self.showsyntaxerror()
self.execution_count += 1
if store_history and self.increment_exec_count:
self.execution_count += 1
return None

interactivity = 'last' # Last node to be run interactive
Expand All @@ -2153,7 +2159,8 @@ def run_cell(self, cell, store_history=True):
# history output logging is enabled.
self.history_manager.store_output(self.execution_count)
# Each cell is a *single* input, regardless of how many lines it has
self.execution_count += 1
if self.increment_exec_count:
self.execution_count += 1

def run_ast_nodes(self, nodelist, cell_name, interactivity='last'):
"""Run a sequence of AST nodes. The execution mode depends on the
Expand Down

0 comments on commit 527f067

Please sign in to comment.