eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py

changeset 8246
e4b95b0ebd31
parent 8226
6dc5b1db7bdc
child 8250
4d65b3ec1d31
diff -r dce55f623991 -r e4b95b0ebd31 eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Fri Apr 16 18:08:45 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Sat Apr 17 12:21:37 2021 +0200
@@ -33,11 +33,9 @@
 from .Miscellaneous.MiscellaneousDefaults import (
     MiscellaneousCheckerDefaultArgs
 )
-
-try:
-    basestring          # __IGNORE_WARNING__
-except Exception:
-    basestring = str    # define for Python3
+from .Annotations.AnnotationsCheckerDefaults import (
+    AnnotationsCheckerDefaultArgs
+)
 
 
 class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog):
@@ -515,10 +513,31 @@
             )
         
         if "AnnotationsChecker" not in self.__data:
-            self.__data["AnnotationsChecker"] = {
-                "MinimumCoverage": 75,
-                "MaximumComplexity": 3,
-            }
+            self.__data["AnnotationsChecker"] = copy.deepcopy(
+                AnnotationsCheckerDefaultArgs)
+        else:
+            # We are upgrading from an older data structure
+            if "MaximumLength" not in self.__data["AnnotationsChecker"]:
+                # MaximumLength is the sentinel for the first extension
+                self.__data["AnnotationsChecker"].extend({
+                    "MaximumLength":
+                        AnnotationsCheckerDefaultArgs["MaximumLength"],
+                    "SuppressNoneReturning":
+                        AnnotationsCheckerDefaultArgs["SuppressNoneReturning"],
+                    "SuppressDummyArgs":
+                        AnnotationsCheckerDefaultArgs["SuppressDummyArgs"],
+                    "AllowUntypedDefs":
+                        AnnotationsCheckerDefaultArgs["AllowUntypedDefs"],
+                    "AllowUntypedNested":
+                        AnnotationsCheckerDefaultArgs["AllowUntypedNested"],
+                    "MypyInitReturn":
+                        AnnotationsCheckerDefaultArgs["MypyInitReturn"],
+                    "DispatchDecorators":
+                        AnnotationsCheckerDefaultArgs["DispatchDecorators"],
+                    "OverloadDecorators":
+                        AnnotationsCheckerDefaultArgs["OverloadDecorators"],
+                })
+        # TODO: add additional AnnotationsChecker parameters
         
         if "SecurityChecker" not in self.__data:
             from .Security.SecurityDefaults import SecurityDefaults
@@ -575,10 +594,31 @@
             self.__data["CommentedCodeChecker"]["Aggressive"])
         self.__initCommentedCodeCheckerWhiteList(
             self.__data["CommentedCodeChecker"]["WhiteList"])
+        
+        # type annotations
         self.minAnnotationsCoverageSpinBox.setValue(
             self.__data["AnnotationsChecker"]["MinimumCoverage"])
         self.maxAnnotationsComplexitySpinBox.setValue(
             self.__data["AnnotationsChecker"]["MaximumComplexity"])
+        self.maxAnnotationsLengthSpinBox.setValue(
+            self.__data["AnnotationsChecker"]["MaximumLength"])
+        self.suppressNoneReturningCheckBox.setChecked(
+            self.__data["AnnotationsChecker"]["SuppressNoneReturning"])
+        self.suppressDummyArgsCheckBox.setChecked(
+            self.__data["AnnotationsChecker"]["SuppressDummyArgs"])
+        self.allowUntypedDefsCheckBox.setChecked(
+            self.__data["AnnotationsChecker"]["AllowUntypedDefs"])
+        self.allowUntypedNestedCheckBox.setChecked(
+            self.__data["AnnotationsChecker"]["AllowUntypedNested"])
+        self.mypyInitReturnCheckBox.setChecked(
+            self.__data["AnnotationsChecker"]["MypyInitReturn"])
+        self.dispatchDecoratorEdit.setText(
+            ", ".join(
+                self.__data["AnnotationsChecker"]["DispatchDecorators"]))
+        self.overloadDecoratorEdit.setText(
+            ", ".join(
+                self.__data["AnnotationsChecker"]["OverloadDecorators"]))
+        # TODO: add additional AnnotationsChecker parameters
         
         # security
         self.tmpDirectoriesEdit.setPlainText("\n".join(
@@ -730,12 +770,32 @@
                     "WhiteList": self.__getCommentedCodeCheckerWhiteList(),
                 }
             }
+            
             annotationArgs = {
                 "MinimumCoverage":
                     self.minAnnotationsCoverageSpinBox.value(),
                 "MaximumComplexity":
                     self.maxAnnotationsComplexitySpinBox.value(),
+                "MaximumLength":
+                    self.maxAnnotationsLengthSpinBox.value(),
+                "SuppressNoneReturning":
+                    self.suppressNoneReturningCheckBox.isChecked(),
+                "SuppressDummyArgs":
+                    self.suppressDummyArgsCheckBox.isChecked(),
+                "AllowUntypedDefs":
+                    self.allowUntypedDefsCheckBox.isChecked(),
+                "AllowUntypedNested":
+                    self.allowUntypedNestedCheckBox.isChecked(),
+                "MypyInitReturn":
+                    self.mypyInitReturnCheckBox.isChecked(),
+                "DispatchDecorators":
+                    [d.strip()
+                     for d in self.dispatchDecoratorEdit.text().split(",")],
+                "OverloadDecorators":
+                    [d.strip()
+                     for d in self.overloadDecoratorEdit.text().split(",")],
             }
+            # TODO: add additional AnnotationsChecker parameters
             
             securityArgs = {
                 "hardcoded_tmp_directories": [
@@ -803,7 +863,7 @@
         """
         options = self.__options[:]
         flags = Utilities.extractFlags(source)
-        if "noqa" in flags and isinstance(flags["noqa"], basestring):
+        if "noqa" in flags and isinstance(flags["noqa"], str):
             excludeMessages = options[0].strip().rstrip(",")
             if excludeMessages:
                 excludeMessages += ","
@@ -1147,7 +1207,28 @@
                         self.minAnnotationsCoverageSpinBox.value(),
                     "MaximumComplexity":
                         self.maxAnnotationsComplexitySpinBox.value(),
+                    "MaximumLength":
+                        self.maxAnnotationsLengthSpinBox.value(),
+                    "SuppressNoneReturning":
+                        self.suppressNoneReturningCheckBox.isChecked(),
+                    "SuppressDummyArgs":
+                        self.suppressDummyArgsCheckBox.isChecked(),
+                    "AllowUntypedDefs":
+                        self.allowUntypedDefsCheckBox.isChecked(),
+                    "AllowUntypedNested":
+                        self.allowUntypedNestedCheckBox.isChecked(),
+                    "MypyInitReturn":
+                        self.mypyInitReturnCheckBox.isChecked(),
+                    "DispatchDecorators":
+                        [d.strip()
+                         for d in self.dispatchDecoratorEdit.text().split(",")
+                         ],
+                    "OverloadDecorators":
+                        [d.strip()
+                         for d in self.overloadDecoratorEdit.text().split(",")
+                         ],
                 },
+                # TODO: add additional AnnotationsChecker parameters
                 "SecurityChecker": {
                     "HardcodedTmpDirectories": [
                         t.strip()
@@ -1434,12 +1515,49 @@
                     "CommentedCodeChecker"]["WhiteList"]
             )
         ))
+        
+        # type annotations
         self.minAnnotationsCoverageSpinBox.setValue(int(
             Preferences.Prefs.settings.value(
-                "PEP8/MinimumAnnotationsCoverage", 75)))
+                "PEP8/MinimumAnnotationsCoverage",
+                AnnotationsCheckerDefaultArgs["MinimumCoverage"])))
         self.maxAnnotationsComplexitySpinBox.setValue(int(
             Preferences.Prefs.settings.value(
-                "PEP8/MaximumAnnotationComplexity", 3)))
+                "PEP8/MaximumAnnotationComplexity",
+                AnnotationsCheckerDefaultArgs["MaximumComplexity"])))
+        self.maxAnnotationsLengthSpinBox.setValue(int(
+            Preferences.Prefs.settings.value(
+                "PEP8/MaximumAnnotationLength",
+                AnnotationsCheckerDefaultArgs["MaximumLength"])))
+        self.suppressNoneReturningCheckBox.setChecked(Preferences.toBool(
+            Preferences.Prefs.settings.value(
+                "PEP8/SuppressNoneReturning",
+                AnnotationsCheckerDefaultArgs["SuppressNoneReturning"])))
+        self.suppressDummyArgsCheckBox.setChecked(Preferences.toBool(
+            Preferences.Prefs.settings.value(
+                "PEP8/SuppressDummyArgs",
+                AnnotationsCheckerDefaultArgs["SuppressDummyArgs"])))
+        self.allowUntypedDefsCheckBox.setChecked(Preferences.toBool(
+            Preferences.Prefs.settings.value(
+                "PEP8/AllowUntypedDefs",
+                AnnotationsCheckerDefaultArgs["AllowUntypedDefs"])))
+        self.allowUntypedNestedCheckBox.setChecked(Preferences.toBool(
+            Preferences.Prefs.settings.value(
+                "PEP8/AllowUntypedNested",
+                AnnotationsCheckerDefaultArgs["AllowUntypedNested"])))
+        self.mypyInitReturnCheckBox.setChecked(Preferences.toBool(
+            Preferences.Prefs.settings.value(
+                "PEP8/MypyInitReturn",
+                AnnotationsCheckerDefaultArgs["MypyInitReturn"])))
+        self.dispatchDecoratorEdit.setText(", ".join(Preferences.toList(
+            Preferences.Prefs.settings.value(
+                "PEP8/DispatchDecorators",
+                AnnotationsCheckerDefaultArgs["DispatchDecorators"]))))
+        self.overloadDecoratorEdit.setText(", ".join(Preferences.toList(
+            Preferences.Prefs.settings.value(
+                "PEP8/OverloadDecorators",
+                AnnotationsCheckerDefaultArgs["OverloadDecorators"]))))
+        # TODO: add additional AnnotationsChecker parameters
         
         # security
         from .Security.SecurityDefaults import SecurityDefaults
@@ -1547,12 +1665,41 @@
         Preferences.Prefs.settings.setValue(
             "PEP8/CommentedCodeWhitelist",
             self.__getCommentedCodeCheckerWhiteList())
+        
+        # type annotations
         Preferences.Prefs.settings.setValue(
             "PEP8/MinimumAnnotationsCoverage",
             self.minAnnotationsCoverageSpinBox.value())
         Preferences.Prefs.settings.setValue(
             "PEP8/MaximumAnnotationComplexity",
             self.maxAnnotationsComplexitySpinBox.value())
+        Preferences.Prefs.settings.setValue(
+            "PEP8/MaximumAnnotationLength",
+            self.maxAnnotationsLengthSpinBox.value())
+        Preferences.Prefs.settings.setValue(
+            "PEP8/SuppressNoneReturning",
+            self.suppressNoneReturningCheckBox.isChecked())
+        Preferences.Prefs.settings.setValue(
+            "PEP8/SuppressDummyArgs",
+            self.suppressDummyArgsCheckBox.isChecked())
+        Preferences.Prefs.settings.setValue(
+            "PEP8/AllowUntypedDefs",
+            self.allowUntypedDefsCheckBox.isChecked())
+        Preferences.Prefs.settings.setValue(
+            "PEP8/AllowUntypedNested",
+            self.allowUntypedNestedCheckBox.isChecked())
+        Preferences.Prefs.settings.setValue(
+            "PEP8/MypyInitReturn",
+            self.mypyInitReturnCheckBox.isChecked())
+        Preferences.Prefs.settings.setValue(
+            "PEP8/DispatchDecorators",
+            [d.strip()
+             for d in self.dispatchDecoratorEdit.text().split(",")])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/OverloadDecorators",
+            [d.strip()
+             for d in self.overloadDecoratorEdit.text().split(",")])
+        # TODO: add additional AnnotationsChecker parameters
         
         # security
         Preferences.Prefs.settings.setValue(
@@ -1650,10 +1797,39 @@
             MiscellaneousCheckerDefaultArgs[
                 "CommentedCodeChecker"]["WhiteList"]
         )
+        
+        # type annotations
         Preferences.Prefs.settings.setValue(
-            "PEP8/MinimumAnnotationsCoverage", 75)
+            "PEP8/MinimumAnnotationsCoverage",
+            AnnotationsCheckerDefaultArgs["MinimumCoverage"])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/MaximumAnnotationComplexity",
+            AnnotationsCheckerDefaultArgs["MaximumComplexity"])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/MaximumAnnotationLength",
+            AnnotationsCheckerDefaultArgs["MaximumLength"])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/SuppressNoneReturning",
+            AnnotationsCheckerDefaultArgs["SuppressNoneReturning"])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/SuppressDummyArgs",
+            AnnotationsCheckerDefaultArgs["SuppressDummyArgs"])
         Preferences.Prefs.settings.setValue(
-            "PEP8/MaximumAnnotationComplexity", 3)
+            "PEP8/AllowUntypedDefs",
+            AnnotationsCheckerDefaultArgs["AllowUntypedDefs"])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/AllowUntypedNested",
+            AnnotationsCheckerDefaultArgs["AllowUntypedNested"])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/MypyInitReturn",
+            AnnotationsCheckerDefaultArgs["MypyInitReturn"])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/DispatchDecorators",
+            AnnotationsCheckerDefaultArgs["DispatchDecorators"])
+        Preferences.Prefs.settings.setValue(
+            "PEP8/OverloadDecorators",
+            AnnotationsCheckerDefaultArgs["OverloadDecorators"])
+        # TODO: add additional AnnotationsChecker parameters
         
         # security
         from .Security.SecurityDefaults import SecurityDefaults

eric ide

mercurial