CompleterPython: fixed an incorrect behavior if code to be checked contained tripple quoted string with valid Python code. eric7

Fri, 28 Apr 2023 15:16:09 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 28 Apr 2023 15:16:09 +0200
branch
eric7
changeset 9992
3d2f1101a23a
parent 9991
814552ada1fb
child 9993
68f8765de8ad

CompleterPython: fixed an incorrect behavior if code to be checked contained tripple quoted string with valid Python code.

src/eric7/QScintilla/TypingCompleters/CompleterPython.py file | annotate | diff | comparison | revisions
--- a/src/eric7/QScintilla/TypingCompleters/CompleterPython.py	Fri Apr 28 14:57:14 2023 +0200
+++ b/src/eric7/QScintilla/TypingCompleters/CompleterPython.py	Fri Apr 28 15:16:09 2023 +0200
@@ -118,7 +118,10 @@
             if self.__insertClosingBrace:
                 if (
                     self.__defRX.fullmatch(txt) is not None
-                    or self.__classRX.fullmatch(txt) is not None
+                    or (
+                        self.__classRX.fullmatch(txt) is not None
+                        and txt.endswith("(")
+                    )
                 ):
                     self.editor.insert("):")
                 else:
@@ -336,20 +339,24 @@
         line, col = self.editor.getCursorPosition()
         indentation = self.editor.indentation(line)
         tryLine = line - 1
+        inMultiLineString = False
         while tryLine >= 0:
             txt = self.editor.text(tryLine)
-            edInd = self.editor.indentation(tryLine)
-            newInd = -1
-            if rxIndex(self.__defRX, txt) == 0 and edInd < indentation:
-                newInd = edInd
-            elif rxIndex(self.__classRX, txt) == 0 and edInd < indentation:
-                newInd = edInd + (
-                    self.editor.indentationWidth() or self.editor.tabWidth()
-                )
-            if newInd >= 0:
-                self.editor.cancelList()
-                self.editor.setIndentation(line, newInd)
-                break
+            if txt.count('"""') % 2 != 0 or txt.count("'''") % 2 != 0:
+                inMultiLineString = not inMultiLineString
+            if not inMultiLineString:
+                edInd = self.editor.indentation(tryLine)
+                newInd = -1
+                if rxIndex(self.__defRX, txt) == 0 and edInd < indentation:
+                    newInd = edInd
+                elif rxIndex(self.__classRX, txt) == 0 and edInd < indentation:
+                    newInd = edInd + (
+                        self.editor.indentationWidth() or self.editor.tabWidth()
+                    )
+                if newInd >= 0:
+                    self.editor.cancelList()
+                    self.editor.setIndentation(line, newInd)
+                    break
             tryLine -= 1
 
     def __isClassMethod(self):
@@ -361,24 +368,28 @@
         line, col = self.editor.getCursorPosition()
         indentation = self.editor.indentation(line)
         curLine = line - 1
+        inMultiLineString = False
         while curLine >= 0:
             txt = self.editor.text(curLine)
-            if (
-                (
-                    rxIndex(self.__defSelfRX, txt) == 0
-                    or rxIndex(self.__defClsRX, txt) == 0
-                )
-                and self.editor.indentation(curLine) == indentation
-            ) or (
-                rxIndex(self.__classRX, txt) == 0
-                and self.editor.indentation(curLine) < indentation
-            ):
-                return True
-            elif (
-                rxIndex(self.__defRX, txt) == 0
-                and self.editor.indentation(curLine) <= indentation
-            ):
-                return False
+            if txt.count('"""') % 2 != 0 or txt.count("'''") % 2 != 0:
+                inMultiLineString = not inMultiLineString
+            if not inMultiLineString:
+                if (
+                    (
+                        rxIndex(self.__defSelfRX, txt) == 0
+                        or rxIndex(self.__defClsRX, txt) == 0
+                    )
+                    and self.editor.indentation(curLine) == indentation
+                ) or (
+                    rxIndex(self.__classRX, txt) == 0
+                    and self.editor.indentation(curLine) < indentation
+                ):
+                    return True
+                elif (
+                    rxIndex(self.__defRX, txt) == 0
+                    and self.editor.indentation(curLine) <= indentation
+                ):
+                    return False
             curLine -= 1
         return False
 

eric ide

mercurial