Refined the "mutable default arguments" checker a little bit.

Mon, 20 Mar 2017 18:50:25 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 20 Mar 2017 18:50:25 +0100
changeset 5639
9ee960bceb51
parent 5638
8d2a65057e50
child 5640
2e046f1818ed

Refined the "mutable default arguments" checker a little bit.

Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/CodeStyleChecker/translations.py file | annotate | diff | comparison | revisions
diff -r 8d2a65057e50 -r 9ee960bceb51 Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py
--- a/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py	Mon Mar 20 18:47:38 2017 +0100
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py	Mon Mar 20 18:50:25 2017 +0100
@@ -35,7 +35,7 @@
         
         "M801",
         "M811",
-        "M821",
+        "M821", "M822",
         
         "M901",
     ]
@@ -108,7 +108,7 @@
             (self.__checkFuture, ("M701", "M702")),
             (self.__checkPrintStatements, ("M801",)),
             (self.__checkTuple, ("M811", )),
-            (self.__checkMutableDefault, ("M821", )),
+            (self.__checkMutableDefault, ("M821", "M822")),
         ]
         
         self.__defaultArgs = {
@@ -609,8 +609,12 @@
                             typeName = default.__name__
                         else:
                             typeName = type(default).__name__
-                        self.__error(node.lineno - 1, node.col_offset, "M821",
-                                     typeName)
+                        if isinstance(default, ast.Call):
+                            errorCode = "M822"
+                        else:
+                            errorCode = "M821"
+                        self.__error(node.lineno - 1, node.col_offset,
+                                     errorCode, typeName)
 
 
 class TextVisitor(ast.NodeVisitor):
diff -r 8d2a65057e50 -r 9ee960bceb51 Plugins/CheckerPlugins/CodeStyleChecker/translations.py
--- a/Plugins/CheckerPlugins/CodeStyleChecker/translations.py	Mon Mar 20 18:47:38 2017 +0100
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/translations.py	Mon Mar 20 18:50:25 2017 +0100
@@ -518,6 +518,9 @@
     "M821": QCoreApplication.translate(
         "MiscellaneousChecker",
         "mutable default argument of type {0}"),
+    "M822": QCoreApplication.translate(
+        "MiscellaneousChecker",
+        "mutable default argument of type {0}"),
     "M901": QCoreApplication.translate(
         "MiscellaneousChecker",
         "{0}: {1}"),
@@ -710,6 +713,7 @@
     "M701": ["print_function, unicode_literals", "print_function"],
     "M702": ["print_function, unicode_literals"],
     "M821": ["Dict"],
+    "M822": ["Call"],
     "M901": ["SyntaxError", "Invalid Syntax"],
     "FWRITE_ERROR": ["IOError"],
 }

eric ide

mercurial