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 | 57da6d484ee10b94e4d81e2697b2b44e3be89c1f (patch) | |
| tree | 2320dd0e5cb07b69ca3c9d4380d69992415a33aa /checkers/exceptions.py | |
| parent | 2b172ad79b66ff7c0ae257bb23bc67f89b80c6bf (diff) | |
| download | pylint-git-57da6d484ee10b94e4d81e2697b2b44e3be89c1f.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 b681c6d7e..54d0aedc4 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 = [] |
