summaryrefslogtreecommitdiff
path: root/astroid/exceptions.py
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-06-28 01:36:47 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-06-28 01:36:47 +0300
commitbee310f81739f58cf8568b1e32b0634ff05c8d82 (patch)
tree1f60ed9357cdd0f472ceac7dcd9643c9ca6f0c49 /astroid/exceptions.py
parenta26db5ccc7d4f1eae885df51bf9cea97b4bd8f79 (diff)
downloadastroid-git-bee310f81739f58cf8568b1e32b0634ff05c8d82.tar.gz
Add support for retrieving TypeErrors for binary arithmetic operations and augmented assignments.
The change is similar to what was added for UnaryOps: a new method called *type_errors* for both AugAssign and BinOp, which can be used to retrieve type errors occurred during inference. Also, a new exception object was added, BinaryOperationError.
Diffstat (limited to 'astroid/exceptions.py')
-rw-r--r--astroid/exceptions.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/astroid/exceptions.py b/astroid/exceptions.py
index f6f0269d..9b18d857 100644
--- a/astroid/exceptions.py
+++ b/astroid/exceptions.py
@@ -90,3 +90,16 @@ class UnaryOperationError(OperationError):
operand_type = self.operand.name
msg = "bad operand type for unary {}: {}"
return msg.format(self.op, operand_type)
+
+
+class BinaryOperationError(OperationError):
+ """Object which describes type errors for BinOps."""
+
+ def __init__(self, left_type, op, right_type):
+ self.left_type = left_type
+ self.right_type = right_type
+ self.op = op
+
+ def __str__(self):
+ msg = "unsupported operand type(s) for {}: {!r} and {!r}"
+ return msg.format(self.op, self.left_type.name, self.right_type.name)