[accerciser/gnome-3-32] IPython: Avoid using input splitter when not really needed



commit 1edba29c25eded0c6931a7f4ddb3d17c8fc755dc
Author: Samuel Thibault <samuel thibault ens-lyon org>
Date:   Sat Jun 8 21:19:02 2019 +0200

    IPython: Avoid using input splitter when not really needed
    
    We can replace it, like IPython's interactiveshell, with a much simpler
    loop. Hopefully that will get us compatible on longer term. It at least
    works with IPython 7.2.0
    
    Fixes #5
    
    (cherry picked from commit 3008be6e0cbf6d42b55354405b37693b5c4c62c6)

 plugins/ipython_view.py | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/plugins/ipython_view.py b/plugins/ipython_view.py
index ae3d2be..85cb482 100755
--- a/plugins/ipython_view.py
+++ b/plugins/ipython_view.py
@@ -131,6 +131,12 @@ class IterableIPShell:
     #
     self.__update_namespace()
 
+    # Avoid using input splitter when not really needed.
+    # Perhaps it could work even before 5.8.0
+    # But it definitely does not work any more with >= 7.0.0
+    self.no_input_splitter = parse_version(IPython.release.version) >= parse_version('5.8.0')
+    self.lines = []
+
   def __update_namespace(self):
     '''
     Update self.IP namespace for autocompletion with sys.modules
@@ -172,14 +178,21 @@ class IterableIPShell:
     except:
       self.IP.showtraceback()
     else:
-      self.IP.input_splitter.push(line)
-      self.iter_more = self.IP.input_splitter.push_accepts_more()
+      if self.no_input_splitter:
+        self.lines.append(self.IP.raw_input(self.prompt))
+        self.iter_more = self.IP.check_complete('\n'.join(self.lines))[0] == 'incomplete'
+      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 (self.IP.SyntaxTB.last_syntax_error and
           self.IP.autoedit_syntax):
           self.IP.edit_syntax_error()
       if not self.iter_more:
-          if parse_version(IPython.release.version) >= parse_version("2.0.0-dev"):
+          if self.no_input_splitter:
+            source_raw = '\n'.join(self.lines)
+            self.lines = []
+          elif parse_version(IPython.release.version) >= parse_version("2.0.0-dev"):
             source_raw = self.IP.input_splitter.raw_reset()
           else:
             source_raw = self.IP.input_splitter.source_raw_reset()[1]


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