diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2014-11-15 16:19:28 +0200 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2014-11-15 16:19:28 +0200 |
commit | 7997dad2a80ee8a779a01cb76b1f2d73b09e380b (patch) | |
tree | 15d49907a1104da60a5ed7106c5184955bd108bf | |
parent | 31e9fb27ba204e521fcb7931665dd535890fa481 (diff) | |
download | pylint-git-7997dad2a80ee8a779a01cb76b1f2d73b09e380b.tar.gz |
Move old-raise-syntax to the python3 porting checker.
-rw-r--r-- | checkers/base.py | 12 | ||||
-rw-r--r-- | checkers/python3.py | 19 | ||||
-rw-r--r-- | test/messages/func_w0701_py_30.txt | 2 |
3 files changed, 19 insertions, 14 deletions
diff --git a/checkers/base.py b/checkers/base.py index 0097df038..32edee2b8 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -508,12 +508,6 @@ functions, methods 'A call of assert on a tuple will always evaluate to true if ' 'the tuple is not empty, and will always evaluate to false if ' 'it is.'), - 'W0121': ('Use raise ErrorClass(args) instead of raise ErrorClass, args.', - 'old-raise-syntax', - "Used when the alternate raise syntax 'raise foo, bar' is used " - "instead of 'raise foo(bar)'.", - {'maxversion': (3, 0)}), - 'C0121': ('Missing required attribute "%s"', # W0103 'missing-module-attribute', 'Used when an attribute required for modules is missing.'), @@ -727,16 +721,12 @@ functions, methods # 2 - Is it inside final body of a try...finally bloc ? self._check_not_in_finally(node, 'break', (astroid.For, astroid.While,)) - @check_messages('unreachable', 'old-raise-syntax') + @check_messages('unreachable') def visit_raise(self, node): """check if the node has a right sibling (if so, that's some unreachable code) """ self._check_unreachable(node) - if sys.version_info >= (3, 0): - return - if node.exc is not None and node.inst is not None and node.tback is None: - self.add_message('old-raise-syntax', node=node) @check_messages('exec-used') def visit_exec(self, node): diff --git a/checkers/python3.py b/checkers/python3.py index 00930d646..899bb9b00 100644 --- a/checkers/python3.py +++ b/checkers/python3.py @@ -57,6 +57,14 @@ class Python3Checker(checkers.BaseChecker): 'See http://www.python.org/dev/peps/pep-3110/', {'maxversion': (3, 0), 'old_names': [('W0712', 'unpacking-in-except')]}), + 'E1604': ('Use raise ErrorClass(args) instead of ' + 'raise ErrorClass, args.', + 'old-raise-syntax', + "Used when the alternate raise syntax " + "'raise foo, bar' is used " + "instead of 'raise foo(bar)'.", + {'maxversion': (3, 0), + 'old_names': [('W0121', 'old-raise-syntax')]}), 'W1601': ('apply built-in referenced', 'apply-builtin', 'Used when the apply built-in function is referenced ' @@ -306,9 +314,16 @@ class Python3Checker(checkers.BaseChecker): if isinstance(node.name, (astroid.Tuple, astroid.List)): self.add_message('unpacking-in-except', node=node) - @utils.check_messages('raising-string') + @utils.check_messages('raising-string', 'old-raise-syntax') def visit_raise(self, node): - """Visit a raise statement and check for raising strings.""" + """Visit a raise statement and check for raising + strings or old-raise-syntax. + """ + if (node.exc is not None and + node.inst is not None and + node.tback is None): + self.add_message('old-raise-syntax', node=node) + # Ignore empty raise. if node.exc is None: return diff --git a/test/messages/func_w0701_py_30.txt b/test/messages/func_w0701_py_30.txt index d643517c0..8ade83dfa 100644 --- a/test/messages/func_w0701_py_30.txt +++ b/test/messages/func_w0701_py_30.txt @@ -1,3 +1,3 @@ +E: 12:function2: Use raise ErrorClass(args) instead of raise ErrorClass, args. W: 8:function1: Raising a string exception W: 12:function2: Raising a string exception -W: 12:function2: Use raise ErrorClass(args) instead of raise ErrorClass, args. |