diff options
author | Torsten Marek <tmarek@google.com> | 2013-06-18 16:26:55 +0200 |
---|---|---|
committer | Torsten Marek <tmarek@google.com> | 2013-06-18 16:26:55 +0200 |
commit | ea4b77dbea82e9750e2f7df23b8cc675a196236b (patch) | |
tree | 0fedd094ab9d9e20d477b822c98a241c7dd5d699 /checkers/exceptions.py | |
parent | c0e078e31af590d7adec84966bdfef94c3f0021b (diff) | |
download | pylint-ea4b77dbea82e9750e2f7df23b8cc675a196236b.tar.gz |
Added a new warning unpacking-in-except (W0712) about unpacking
exceptions in handlers, which is unsupported in Python 3.
Diffstat (limited to 'checkers/exceptions.py')
-rw-r--r-- | checkers/exceptions.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/checkers/exceptions.py b/checkers/exceptions.py index b681c6d..54d0aed 100644 --- a/checkers/exceptions.py +++ b/checkers/exceptions.py @@ -22,7 +22,7 @@ import astroid from astroid import YES, Instance, unpack_infer from pylint.checkers import BaseChecker -from pylint.checkers.utils import is_empty, is_raising +from pylint.checkers.utils import is_empty, is_raising, check_messages from pylint.interfaces import IAstroidChecker @@ -71,6 +71,11 @@ MSGS = { 'Used when the exception to catch is of the form \ "except A or B:". If intending to catch multiple, \ rewrite as "except (A, B):"'), + 'W0712': ('Implicit unpacking of exceptions is not supported in Python 3', + 'unpacking-in-except', + 'Python3 will not allow implicit unpacking of exceptions in except ' + 'clauses. ' + 'See http://www.python.org/dev/peps/pep-3110/'), } @@ -154,6 +159,12 @@ class ExceptionsChecker(BaseChecker): return value_found + @check_messages('W0712') + def visit_excepthandler(self, node): + """Visit an except handler block and check for exception unpacking.""" + if isinstance(node.name, (astroid.Tuple, astroid.List)): + self.add_message('W0712', node=node) + def visit_tryexcept(self, node): """check for empty except""" exceptions_classes = [] |