[accerciser: 1/2] ipython_view: Fix off-by-one number in input prompt




commit 232db06e1d1a82f66147851b164a8f85d7c5b1e9
Author: Michael Weghorn <m weghorn posteo de>
Date:   Thu Aug 4 07:34:13 2022 +0200

    ipython_view: Fix off-by-one number in input prompt
    
    Previously, the numbering for the input prompt
    was incorrect, one too low except for the
    first prompt, so there was a mismatch between
    the numbers for input and output: An "In [n]"
    would be followed by an "Out [n+1]", e.g.
    
        In [1]: 1
        Out[1]: 1
        In [1]: 2
        Out[2]: 2
        In [2]: 3
        Out[3]: 3
        In [3]: _i2 # should give the input with index 2
        Out[4]: '2'
        In [4]:
    
    Fix this by generating the next input prompt
    *after* the current input has been processed
    (`self.IP.run_cell(source_raw, store_history=True)`),
    at which point the counter (`self.IP.execution_count`)
    has the correct value:
    
        In [1]: 1
        Out[1]: 1
        In [2]: 2
        Out[2]: 2
        In [3]: 3
        Out[3]: 3
        In [4]: _i2
        Out[4]: '2'
        In [5]:

 plugins/ipython_view.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/plugins/ipython_view.py b/plugins/ipython_view.py
index 956991e..a49eb02 100755
--- a/plugins/ipython_view.py
+++ b/plugins/ipython_view.py
@@ -204,7 +204,6 @@ class IterableIPShell:
       else:
         self.IP.input_splitter.push(line)
         self.iter_more = self.IP.input_splitter.push_accepts_more()
-      self.prompt = self.generatePrompt(self.iter_more)
       if not self.iter_more:
           if self.no_input_splitter:
             source_raw = '\n'.join(self.lines)
@@ -220,6 +219,7 @@ class IterableIPShell:
           #
           self.IP.rl_do_indent = True
           pass
+      self.prompt = self.generatePrompt(self.iter_more)
 
     if IPython.version_info < (8,):
       sys.stdout = orig_stdout


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]