105 "M621", "M622", "M623", "M624", "M625", |
106 "M621", "M622", "M623", "M624", "M625", |
106 "M631", "M632")), |
107 "M631", "M632")), |
107 (self.__checkFuture, ("M701", "M702")), |
108 (self.__checkFuture, ("M701", "M702")), |
108 (self.__checkPrintStatements, ("M801",)), |
109 (self.__checkPrintStatements, ("M801",)), |
109 (self.__checkTuple, ("M811", )), |
110 (self.__checkTuple, ("M811", )), |
|
111 (self.__checkMutableDefault, ("M821", )), |
110 ] |
112 ] |
111 |
113 |
112 self.__defaultArgs = { |
114 self.__defaultArgs = { |
113 "CodingChecker": 'latin-1, utf-8', |
115 "CodingChecker": 'latin-1, utf-8', |
114 "CopyrightChecker": { |
116 "CopyrightChecker": { |
584 elif (isinstance(node.args[0], ast.ListComp) and |
586 elif (isinstance(node.args[0], ast.ListComp) and |
585 node.func.id in ('all', 'any', 'frozenset', 'max', 'min', |
587 node.func.id in ('all', 'any', 'frozenset', 'max', 'min', |
586 'sorted', 'sum', 'tuple',)): |
588 'sorted', 'sum', 'tuple',)): |
587 self.__error(node.lineno - 1, node.col_offset, "M198", |
589 self.__error(node.lineno - 1, node.col_offset, "M198", |
588 node.func.id) |
590 node.func.id) |
|
591 |
|
592 def __checkMutableDefault(self): |
|
593 """ |
|
594 Private method to check for use of mutable types as default arguments. |
|
595 """ |
|
596 mutableTypes = [ |
|
597 ast.Call, |
|
598 ast.Dict, |
|
599 ast.List, |
|
600 ast.Set, |
|
601 ] |
|
602 |
|
603 for node in ast.walk(self.__tree): |
|
604 if isinstance(node, ast.FunctionDef): |
|
605 for default in node.args.defaults: |
|
606 if any(isinstance(default, mutableType) |
|
607 for mutableType in mutableTypes): |
|
608 if sys.version_info[0] == 2: |
|
609 typeName = default.__name__ |
|
610 else: |
|
611 typeName = type(default).__name__ |
|
612 self.__error(node.lineno - 1, node.col_offset, "M821", |
|
613 typeName) |
589 |
614 |
590 |
615 |
591 class TextVisitor(ast.NodeVisitor): |
616 class TextVisitor(ast.NodeVisitor): |
592 """ |
617 """ |
593 Class implementing a node visitor for bytes and str instances. |
618 Class implementing a node visitor for bytes and str instances. |