diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2014-06-27 19:35:33 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2014-06-27 19:35:33 +0300 |
commit | f607ae828edb94f36732ca2797c5b010e1a49fa4 (patch) | |
tree | 0eaa66992b2dfdd596a4bb896a7615945e5f4043 | |
parent | b86866bda08578facf1facee549904379c6f7d13 (diff) | |
parent | 0951ad6eed20683d5de06afb9c2dff5083ae5b2f (diff) | |
download | pylint-f607ae828edb94f36732ca2797c5b010e1a49fa4.tar.gz |
Merged in bare_except (pull request #2)
Issue broad-except and bare-except even if the number of except handlers is different than 1. Closes issue #113
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/exceptions.py | 8 | ||||
-rw-r--r-- | test/input/func_block_disable_msg.py | 2 | ||||
-rw-r--r-- | test/input/func_format_py27.py | 2 | ||||
-rw-r--r-- | test/input/func_format_py_27.py | 2 | ||||
-rw-r--r-- | test/input/func_w0623_py_30.py | 2 | ||||
-rw-r--r-- | test/messages/func_w0702.txt | 1 | ||||
-rw-r--r-- | test/messages/func_w0705.txt | 10 |
8 files changed, 22 insertions, 8 deletions
@@ -12,6 +12,9 @@ ChangeLog for Pylint 'unused-format-string-argument', 'format-combined-specification', 'missing-format-attribute' and 'invalid-format-index'. + * Issue broad-except and bare-except even if the number + of except handlers is different than 1. Fixes issue #113. + 2014-04-30 -- 1.2.1 * Restore the ability to specify the init-hook option via the configuration file, which was accidentally broken in 1.2.0. diff --git a/checkers/exceptions.py b/checkers/exceptions.py index 7e0f3fc..c91c95d 100644 --- a/checkers/exceptions.py +++ b/checkers/exceptions.py @@ -239,14 +239,14 @@ class ExceptionsChecker(BaseChecker): nb_handlers = len(node.handlers) for index, handler in enumerate(node.handlers): # single except doing nothing but "pass" without else clause - if nb_handlers == 1 and is_empty(handler.body) and not node.orelse: + if is_empty(handler.body) and not node.orelse: self.add_message('pointless-except', node=handler.type or handler.body[0]) if handler.type is None: - if nb_handlers == 1 and not is_raising(handler.body): + if not is_raising(handler.body): self.add_message('bare-except', node=handler) # check if a "except:" is followed by some other # except - elif index < (nb_handlers - 1): + if index < (nb_handlers - 1): msg = 'empty except clause should always appear last' self.add_message('bad-except-order', node=node, args=msg) @@ -270,7 +270,7 @@ class ExceptionsChecker(BaseChecker): self.add_message('bad-except-order', node=handler.type, args=msg) if (exc.name in self.config.overgeneral_exceptions and exc.root().name == EXCEPTIONS_MODULE - and nb_handlers == 1 and not is_raising(handler.body)): + and not is_raising(handler.body)): self.add_message('broad-except', args=exc.name, node=handler.type) if (not inherit_from_std_ex(exc) and diff --git a/test/input/func_block_disable_msg.py b/test/input/func_block_disable_msg.py index 2551823..480eac0 100644 --- a/test/input/func_block_disable_msg.py +++ b/test/input/func_block_disable_msg.py @@ -1,4 +1,4 @@ -# pylint: disable=C0302 +# pylint: disable=C0302,bare-except """pylint option block-disable""" __revision__ = None diff --git a/test/input/func_format_py27.py b/test/input/func_format_py27.py index 46d5cfe..eba178d 100644 --- a/test/input/func_format_py27.py +++ b/test/input/func_format_py27.py @@ -1,4 +1,4 @@ -# pylint:disable=C0103,W0104,W0105 +# pylint:disable=C0103,W0104,W0105,pointless-except """Check format """ __revision__ = '' diff --git a/test/input/func_format_py_27.py b/test/input/func_format_py_27.py index 95f7fde..be5033c 100644 --- a/test/input/func_format_py_27.py +++ b/test/input/func_format_py_27.py @@ -1,4 +1,4 @@ -# pylint:disable=C0103,W0104,W0105 +# pylint:disable=C0103,W0104,W0105,pointless-except """Check format """ __revision__ = '' diff --git a/test/input/func_w0623_py_30.py b/test/input/func_w0623_py_30.py index 9bccbc6..8f1f34c 100644 --- a/test/input/func_w0623_py_30.py +++ b/test/input/func_w0623_py_30.py @@ -1,5 +1,5 @@ """Test for W0623, overwriting names in exception handlers.""" - +# pylint: disable=broad-except,bare-except,pointless-except __revision__ = '' import exceptions diff --git a/test/messages/func_w0702.txt b/test/messages/func_w0702.txt index 7e0ea84..d40a837 100644 --- a/test/messages/func_w0702.txt +++ b/test/messages/func_w0702.txt @@ -1 +1,2 @@ W: 9: No exception type(s) specified +W: 16: Catching too general exception Exception diff --git a/test/messages/func_w0705.txt b/test/messages/func_w0705.txt index fbc200f..0393a88 100644 --- a/test/messages/func_w0705.txt +++ b/test/messages/func_w0705.txt @@ -3,3 +3,13 @@ E: 17: Bad except clauses order (LookupError is an ancestor class of IndexError) E: 24: Bad except clauses order (LookupError is an ancestor class of IndexError) E: 24: Bad except clauses order (NameError is an ancestor class of UnboundLocalError) E: 27: Bad except clauses order (empty except clause should always appear last) +W: 8: Catching too general exception Exception +W: 29: No exception type(s) specified +W: 30: Except doesn't do anything +W: 31: Catching too general exception Exception +W: 31: Except doesn't do anything +W: 38: No exception type(s) specified +W: 43: Catching too general exception Exception +W: 43: Except doesn't do anything +W: 45: No exception type(s) specified +W: 46: Except doesn't do anything
\ No newline at end of file |