src/eric7/QScintilla/Lexers/LexerPython.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9359
8d3f5cf4f819
diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/QScintilla/Lexers/LexerPython.py
--- a/src/eric7/QScintilla/Lexers/LexerPython.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/QScintilla/Lexers/LexerPython.py	Wed Jul 13 14:55:47 2022 +0200
@@ -20,31 +20,32 @@
     """
     Subclass to implement some additional lexer dependant methods.
     """
+
     def __init__(self, variant="", parent=None):
         """
         Constructor
-        
+
         @param variant name of the language variant (string)
         @param parent parent widget of this lexer
         """
         QsciLexerPython.__init__(self, parent)
         SubstyledLexer.__init__(self)
-        
+
         self.variant = variant
         self.commentString = "#"
-        
+
         self.keywordSetDescriptions = [
             self.tr("Keywords"),
             self.tr("Highlighted identifiers"),
         ]
-        
+
         ##############################################################
         ## default sub-style definitions
         ##############################################################
-        
+
         # list of style numbers, that support sub-styling
         self.baseStyles = [11]
-        
+
         self.defaultSubStyles = {
             11: {
                 0: {
@@ -75,7 +76,7 @@
                     "Style": {
                         "fore": 0xDD9900,
                         "font_bold": True,
-                    }
+                    },
                 },
                 1: {
                     "Description": self.tr("__future__ Imports"),
@@ -85,7 +86,7 @@
                     "Style": {
                         "fore": 0xEE00AA,
                         "font_italic": True,
-                    }
+                    },
                 },
                 2: {
                     "Description": self.tr("PyQt5/6 Modules"),
@@ -102,160 +103,166 @@
                     "Style": {
                         "fore": 0x44AADD,
                         "font_bold": True,
-                    }
+                    },
                 },
                 3: {
                     "Description": self.tr("Cython Specifics"),
                     "Words": "cython pyximport Cython __cinit__ __dealloc__",
                     "Style": {
-                        "fore": 0xdd0000,
+                        "fore": 0xDD0000,
                         "font_bold": True,
-                    }
+                    },
                 },
             },
         }
-    
+
     def language(self):
         """
         Public method to get the lexer language.
-        
+
         @return lexer language (string)
         """
         if not self.variant:
             return QsciLexerPython.language(self)
         else:
             return self.variant
-    
+
     def initProperties(self):
         """
         Public slot to initialize the properties.
         """
-        self.setIndentationWarning(
-            Preferences.getEditor("PythonBadIndentation"))
+        self.setIndentationWarning(Preferences.getEditor("PythonBadIndentation"))
         self.setFoldComments(Preferences.getEditor("PythonFoldComment"))
         self.setFoldQuotes(Preferences.getEditor("PythonFoldString"))
         if not Preferences.getEditor("PythonAutoIndent"):
             self.setAutoIndentStyle(QsciScintilla.AiMaintain)
         with contextlib.suppress(AttributeError):
-            self.setV2UnicodeAllowed(
-                Preferences.getEditor("PythonAllowV2Unicode"))
-            self.setV3BinaryOctalAllowed(
-                Preferences.getEditor("PythonAllowV3Binary"))
+            self.setV2UnicodeAllowed(Preferences.getEditor("PythonAllowV2Unicode"))
+            self.setV3BinaryOctalAllowed(Preferences.getEditor("PythonAllowV3Binary"))
             self.setV3BytesAllowed(Preferences.getEditor("PythonAllowV3Bytes"))
         with contextlib.suppress(AttributeError):
             self.setFoldQuotes(Preferences.getEditor("PythonFoldQuotes"))
             self.setStringsOverNewlineAllowed(
-                Preferences.getEditor("PythonStringsOverNewLineAllowed"))
+                Preferences.getEditor("PythonStringsOverNewLineAllowed")
+            )
         with contextlib.suppress(AttributeError):
             self.setHighlightSubidentifiers(
-                Preferences.getEditor("PythonHighlightSubidentifier"))
-    
+                Preferences.getEditor("PythonHighlightSubidentifier")
+            )
+
     def getIndentationDifference(self, line, editor):
         """
         Public method to determine the difference for the new indentation.
-        
+
         @param line line to perform the calculation for (integer)
         @param editor QScintilla editor
         @return amount of difference in indentation (integer)
         """
-        indent_width = editor.getEditorConfig('IndentWidth')
-        
+        indent_width = editor.getEditorConfig("IndentWidth")
+
         lead_spaces = editor.indentation(line)
-        
+
         pline = line - 1
-        while pline >= 0 and re.match(r'^\s*(#.*)?$', editor.text(pline)):
+        while pline >= 0 and re.match(r"^\s*(#.*)?$", editor.text(pline)):
             pline -= 1
-        
+
         if pline < 0:
             last = 0
         else:
             previous_lead_spaces = editor.indentation(pline)
             # trailing spaces
-            m = re.search(r':\s*(#.*)?$', editor.text(pline))
+            m = re.search(r":\s*(#.*)?$", editor.text(pline))
             last = previous_lead_spaces
             if m:
                 last += indent_width
             else:
                 # special cases, like pass (unindent) or return (also unindent)
-                m = re.search(r'(pass\s*(#.*)?$)|(^[^#]return)',
-                              editor.text(pline))
+                m = re.search(r"(pass\s*(#.*)?$)|(^[^#]return)", editor.text(pline))
                 if m:
                     last -= indent_width
-        
+
         indentDifference = (
             last - lead_spaces
-            if (lead_spaces % indent_width != 0 or
-                lead_spaces == 0 or
-                self.lastIndented != line) else
-            -indent_width           # __IGNORE_WARNING_W503__
+            if (
+                lead_spaces % indent_width != 0
+                or lead_spaces == 0
+                or self.lastIndented != line
+            )
+            else -indent_width  # __IGNORE_WARNING_W503__
         )
-        
+
         return indentDifference
-    
+
     def autoCompletionWordSeparators(self):
         """
         Public method to return the list of separators for autocompletion.
-        
+
         @return list of separators (list of strings)
         """
-        return ['.']
-    
+        return ["."]
+
     def isCommentStyle(self, style):
         """
         Public method to check, if a style is a comment style.
-        
+
         @param style style to check (integer)
         @return flag indicating a comment style (boolean)
         """
-        return style in [QsciLexerPython.Comment,
-                         QsciLexerPython.CommentBlock]
-    
+        return style in [QsciLexerPython.Comment, QsciLexerPython.CommentBlock]
+
     def isStringStyle(self, style):
         """
         Public method to check, if a style is a string style.
-        
+
         @param style style to check (integer)
         @return flag indicating a string style (boolean)
         """
-        return style in [QsciLexerPython.DoubleQuotedString,
-                         QsciLexerPython.SingleQuotedString,
-                         QsciLexerPython.TripleDoubleQuotedString,
-                         QsciLexerPython.TripleSingleQuotedString,
-                         QsciLexerPython.UnclosedString]
-    
+        return style in [
+            QsciLexerPython.DoubleQuotedString,
+            QsciLexerPython.SingleQuotedString,
+            QsciLexerPython.TripleDoubleQuotedString,
+            QsciLexerPython.TripleSingleQuotedString,
+            QsciLexerPython.UnclosedString,
+        ]
+
     def defaultKeywords(self, kwSet):
         """
         Public method to get the default keywords.
-        
+
         @param kwSet number of the keyword set (integer)
         @return string giving the keywords (string) or None
         """
         if kwSet == 1:
             if self.language() == "Python3":
                 import keyword
+
                 keywords = " ".join(keyword.kwlist)
             elif self.language() == "MicroPython":
-                keywords = ("False None True and as assert break class "
-                            "continue def del elif else except finally for "
-                            "from global if import in is lambda nonlocal not "
-                            "or pass raise return try while with yield")
+                keywords = (
+                    "False None True and as assert break class "
+                    "continue def del elif else except finally for "
+                    "from global if import in is lambda nonlocal not "
+                    "or pass raise return try while with yield"
+                )
             elif self.language() == "Cython":
-                keywords = ("False None True and as assert break class "
-                            "continue def del elif else except finally for "
-                            "from global if import in is lambda nonlocal not "
-                            "or pass raise return try while with yield "
-                            "cdef cimport cpdef ctypedef")
+                keywords = (
+                    "False None True and as assert break class "
+                    "continue def del elif else except finally for "
+                    "from global if import in is lambda nonlocal not "
+                    "or pass raise return try while with yield "
+                    "cdef cimport cpdef ctypedef"
+                )
             else:
                 keywords = QsciLexerPython.keywords(self, kwSet)
         else:
             keywords = QsciLexerPython.keywords(self, kwSet)
-        
+
         return keywords
-    
+
     def maximumKeywordSet(self):
         """
         Public method to get the maximum keyword set.
-        
+
         @return maximum keyword set (integer)
         """
         return 2

eric ide

mercurial