diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2013-08-01 21:16:06 +0300 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2013-08-01 21:16:06 +0300 |
| commit | dd59eb08ef22f4c8d3146530d5c8e86e44c0baae (patch) | |
| tree | a6d760856878f826f10bb4eef3300b7359a11cec /checkers/exceptions.py | |
| parent | eb24190b16580217cb7c72226e80762087316ab5 (diff) | |
| download | pylint-git-dd59eb08ef22f4c8d3146530d5c8e86e44c0baae.tar.gz | |
Check for non-exception classes inside except clauses.
--HG--
branch : catch
Diffstat (limited to 'checkers/exceptions.py')
| -rw-r--r-- | checkers/exceptions.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/checkers/exceptions.py b/checkers/exceptions.py index eb82d0dff..8ac00a5f0 100644 --- a/checkers/exceptions.py +++ b/checkers/exceptions.py @@ -46,7 +46,11 @@ MSGS = { 'notimplemented-raised', 'Used when NotImplemented is raised instead of \ NotImplementedError'), - + 'E0712': ('Catching an exception which doesn\'t inherit from BaseException: %s', + 'catching-non-exception', + 'Used when a class which doesn\'t inherit from \ + BaseException is used as an exception in an except clause.'), + 'W0701': ('Raising a string exception', 'raising-string', 'Used when a string exception is raised.'), @@ -160,13 +164,14 @@ class ExceptionsChecker(BaseChecker): value_found = False 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) - @check_messages('W0702', 'W0703', 'W0704', 'W0711', 'E0701') + + + @check_messages('W0702', 'W0703', 'W0704', 'W0711', 'E0701', 'catching-non-exception') def visit_tryexcept(self, node): """check for empty except""" exceptions_classes = [] @@ -206,6 +211,13 @@ class ExceptionsChecker(BaseChecker): and exc.root().name == EXCEPTIONS_MODULE and nb_handlers == 1 and not is_raising(handler.body)): self.add_message('W0703', args=exc.name, node=handler.type) + + if (not inherit_from_std_ex(exc) and + exc.root().name != BUILTINS_NAME): + self.add_message('catching-non-exception', + node=handler.type, + args=(exc.name, )) + exceptions_classes += excs |
