summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-06-27 19:18:26 +0300
committercpopa <devnull@localhost>2014-06-27 19:18:26 +0300
commit98c2677a774760eb8ad720eebc7bb6563dbc0a85 (patch)
tree4a69d7fca274e6dd47fb336ca005eb72def0120e
parentb86866bda08578facf1facee549904379c6f7d13 (diff)
downloadpylint-98c2677a774760eb8ad720eebc7bb6563dbc0a85.tar.gz
Issue broad-except and bare-except even if the number of except handlers is different than 1. Closes issue #113.
-rw-r--r--ChangeLog3
-rw-r--r--checkers/exceptions.py8
-rw-r--r--test/input/func_block_disable_msg.py2
-rw-r--r--test/input/func_format_py27.py2
-rw-r--r--test/input/func_format_py_27.py2
-rw-r--r--test/messages/func_w0702.txt1
-rw-r--r--test/messages/func_w0705.txt10
7 files changed, 21 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index db2d59c..0c6a85c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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/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