Mon, 20 Mar 2017 18:50:25 +0100
Refined the "mutable default arguments" checker a little bit.
--- 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):
--- 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"], }