0001-add-boolop-check.patch

download
From ff610453cbf60267512faf621bdfe76a97757283 Mon Sep 17 00:00:00 2001
From: Tim Hatch <thatch@google.com>
Date: Fri, 11 May 2012 16:39:51 -0700
Subject: [PATCH] add boolop check

---
 .../third_party/py/pylint/checkers/exceptions.py   |    7 +++++++
 .../third_party/py/pylint/test/input/func_w0711.py |   15 +++++++++++++++
 .../py/pylint/test/messages/func_w0711.txt         |    4 ++++
 3 files changed, 26 insertions(+), 0 deletions(-)
 create mode 100644 google3/third_party/py/pylint/test/input/func_w0711.py
 create mode 100644 google3/third_party/py/pylint/test/messages/func_w0711.txt

diff --git a/google3/third_party/py/pylint/checkers/exceptions.py b/google3/third_party/py/pylint/checkers/exceptions.py
index 08f4334..e94fa65 100644
--- a/google3/third_party/py/pylint/checkers/exceptions.py
+++ b/google3/third_party/py/pylint/checkers/exceptions.py
@@ -58,6 +58,10 @@ MSGS = {
     'W0710': ('Exception doesn\'t inherit from standard "Exception" class',
               'Used when a custom exception class is raised but doesn\'t \
               inherit from the builtin "Exception" class.'),
+    'W0711': ('Exception to catch is the result of a binary "%s" operation',
+              'Used when the exception to catch is of the form \
+              "except A or B:".  If intending to catch multiple, \
+              rewrite as "except (A, B):"'),
     }
 
 
@@ -157,6 +161,9 @@ class ExceptionsChecker(BaseChecker):
                 elif index < (nb_handlers - 1):
                     msg = 'empty except clause should always appear last'
                     self.add_message('E0701', node=node, args=msg)
+
+            elif isinstance(handler.type, astng.BoolOp):
+                self.add_message('W0711', node=handler, args=handler.type.op)
             else:
                 try:
                     excs = list(unpack_infer(handler.type))
diff --git a/google3/third_party/py/pylint/test/input/func_w0711.py b/google3/third_party/py/pylint/test/input/func_w0711.py
new file mode 100644
index 0000000..9cc791e
--- /dev/null
+++ b/google3/third_party/py/pylint/test/input/func_w0711.py
@@ -0,0 +1,15 @@
+"""find binary operations used as exceptions
+"""
+
+__revision__ = 1
+
+try:
+    __revision__ += 1
+except Exception or StandardError:
+    print "caught1"
+except Exception and StandardError:
+    print "caught2"
+except (Exception or StandardError):
+    print "caught3"
+except (Exception or StandardError), exc:
+    print "caught4"
diff --git a/google3/third_party/py/pylint/test/messages/func_w0711.txt b/google3/third_party/py/pylint/test/messages/func_w0711.txt
new file mode 100644
index 0000000..a158818
--- /dev/null
+++ b/google3/third_party/py/pylint/test/messages/func_w0711.txt
@@ -0,0 +1,4 @@
+W:  8: Exception to catch is the result of a binary "or" operation
+W: 10: Exception to catch is the result of a binary "and" operation
+W: 12: Exception to catch is the result of a binary "or" operation
+W: 14: Exception to catch is the result of a binary "or" operation
-- 
1.7.7.3