summaryrefslogtreecommitdiff
path: root/astroid/node_classes.py
diff options
context:
space:
mode:
authorCeridwen <ceridwenv@gmail.com>2015-11-02 00:10:54 -0500
committerCeridwen <ceridwenv@gmail.com>2015-11-02 00:10:54 -0500
commit1ba0f2d96fbc45ff0b6014b12db98716183e8277 (patch)
tree54b7c4d3ecad6fcda1211ea3a8e5f11f6b407287 /astroid/node_classes.py
parent83f6c45c343cae87f415268959b1056030a5e74c (diff)
downloadastroid-1ba0f2d96fbc45ff0b6014b12db98716183e8277.tar.gz
This bookmark adds structured exceptions to astroid.
Major changes: * AstroidError has an __init__ that accepts arbitrary keyword-only arguments for adding information to exceptions, and a __str__ that lazily uses exception attributes to generate a message. The first positional argument to an exception is assigned to .message. The new API should be fully backwards compatible in general. * Some exceptions are combined or renamed; the old names are still available. * The OperationErrors used by pylint are now BadOperationMessages and located in util.py. * The AstroidBuildingException in _data_build stores the SyntaxError in its .error attribute rather than args[0]. * Many places where exceptions are raised have new, hopefully more useful error messages. The only major issue remaining is how to propagate information into decorators.
Diffstat (limited to 'astroid/node_classes.py')
-rw-r--r--astroid/node_classes.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
index 7da41f5..5a92210 100644
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -412,7 +412,8 @@ class NodeNG(object):
def _infer(self, context=None):
"""we don't know how to resolve a statement by default"""
# this method is overridden by most concrete classes
- raise exceptions.InferenceError(self.__class__.__name__)
+ raise exceptions.InferenceError('No inference function for {node!r}.',
+ node=self, context=context)
def inferred(self):
'''return list of inferred values for a more simple inference usage'''
@@ -894,7 +895,7 @@ class Arguments(mixins.AssignTypeMixin, NodeNG):
i = _find_arg(argname, self.kwonlyargs)[0]
if i is not None and self.kw_defaults[i] is not None:
return self.kw_defaults[i]
- raise exceptions.NoDefault()
+ raise exceptions.NoDefault(func=self.parent, name=argname)
def is_argument(self, name):
"""return True if the name is defined in arguments"""
@@ -1011,13 +1012,13 @@ class AugAssign(mixins.AssignTypeMixin, Statement):
def type_errors(self, context=None):
"""Return a list of TypeErrors which can occur during inference.
- Each TypeError is represented by a :class:`BinaryOperationError`,
+ Each TypeError is represented by a :class:`BadBinaryOperationMessage`,
which holds the original exception.
"""
try:
results = self._infer_augassign(context=context)
return [result for result in results
- if isinstance(result, exceptions.BinaryOperationError)]
+ if isinstance(result, util.BadBinaryOperationMessage)]
except exceptions.InferenceError:
return []
@@ -1053,13 +1054,13 @@ class BinOp(NodeNG):
def type_errors(self, context=None):
"""Return a list of TypeErrors which can occur during inference.
- Each TypeError is represented by a :class:`BinaryOperationError`,
+ Each TypeError is represented by a :class:`BadBinaryOperationMessage`,
which holds the original exception.
"""
try:
results = self._infer_binop(context=context)
return [result for result in results
- if isinstance(result, exceptions.BinaryOperationError)]
+ if isinstance(result, util.BadBinaryOperationMessage)]
except exceptions.InferenceError:
return []
@@ -1745,13 +1746,13 @@ class UnaryOp(NodeNG):
def type_errors(self, context=None):
"""Return a list of TypeErrors which can occur during inference.
- Each TypeError is represented by a :class:`UnaryOperationError`,
+ Each TypeError is represented by a :class:`BadUnaryOperationMessage`,
which holds the original exception.
"""
try:
results = self._infer_unaryop(context=context)
return [result for result in results
- if isinstance(result, exceptions.UnaryOperationError)]
+ if isinstance(result, util.BadUnaryOperationMessage)]
except exceptions.InferenceError:
return []