diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-13 14:21:36 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-13 14:21:36 +0200 |
commit | ba11e314c480fbd3873846c9ad293f0bb4a73db8 (patch) | |
tree | ff7e11608a064d97aad97780c928c8090bf1d279 /astroid/util.py | |
parent | 420608d1b40791167ad43e627e1ca762d5e1dbe9 (diff) | |
parent | d052e7e223d32c7afbe8d8a19ff3747025f59982 (diff) | |
download | astroid-git-ba11e314c480fbd3873846c9ad293f0bb4a73db8.tar.gz |
Merge structured exceptions into 2.0
Diffstat (limited to 'astroid/util.py')
-rw-r--r-- | astroid/util.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/astroid/util.py b/astroid/util.py index 5ece59d2..98a423ce 100644 --- a/astroid/util.py +++ b/astroid/util.py @@ -54,6 +54,41 @@ class Uninferable(object): return self +class BadOperationMessage(object): + """Object which describes a TypeError occurred somewhere in the inference chain + + This is not an exception, but a container object which holds the types and + the error which occurred. + """ + + +class BadUnaryOperationMessage(BadOperationMessage): + """Object which describes operational failures on UnaryOps.""" + + def __init__(self, operand, op, error): + self.operand = operand + self.op = op + self.error = error + + def __str__(self): + operand_type = self.operand.name + msg = "bad operand type for unary {}: {}" + return msg.format(self.op, operand_type) + + +class BadBinaryOperationMessage(BadOperationMessage): + """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) + + def _instancecheck(cls, other): wrapped = cls.__wrapped__ other_cls = other.__class__ |