diff options
author | Ceridwen <ceridwenv@gmail.com> | 2015-11-06 10:48:59 -0500 |
---|---|---|
committer | Ceridwen <ceridwenv@gmail.com> | 2015-11-06 10:48:59 -0500 |
commit | a1874fa7b631d7a4538682ccc8242f489c1f3721 (patch) | |
tree | 03346b76fedd296a50272bf018f92b013c64767e /astroid/protocols.py | |
parent | c094cfd61bb10e0d8b392e3d91606621e2010ff3 (diff) | |
download | astroid-git-a1874fa7b631d7a4538682ccc8242f489c1f3721.tar.gz |
Add structured exceptions to decorators and remaining functions.
* Use explicit StopIteration to pass information from generators to
raise_if_nothing_inferred and path_wrapper, rather than return or
implicit termination by reaching the end of the code block.
* Remove remove_nodes in favor of handling the cases in local_attr,
istance_attr, and getattr, to avoid the need for complicated
information passing when needing to raise an exception.
Diffstat (limited to 'astroid/protocols.py')
-rw-r--r-- | astroid/protocols.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/astroid/protocols.py b/astroid/protocols.py index 2e01124c..5809e4a4 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -249,9 +249,10 @@ def for_assigned_stmts(self, node, context=None, asspath=None): for inferred in _resolve_looppart(self.iter.infer(context), asspath, context): yield inferred - raise exceptions.DefaultStop(node=self, unknown=node, - assign_path=asspath, context=context) - + # Explicit StopIteration to return error information, see comment + # in raise_if_nothing_inferred. + raise StopIteration(dict(node=self, unknown=node, + assign_path=asspath, context=context)) nodes.For.assigned_stmts = for_assigned_stmts nodes.Comprehension.assigned_stmts = for_assigned_stmts @@ -337,8 +338,10 @@ def assign_assigned_stmts(self, node, context=None, asspath=None): return for inferred in _resolve_asspart(self.value.infer(context), asspath, context): yield inferred - raise exceptions.DefaultStop(node=self, unknown=node, - assign_path=asspath, context=context) + # Explicit StopIteration to return error information, see comment + # in raise_if_nothing_inferred. + raise StopIteration(dict(node=self, unknown=node, + assign_path=asspath, context=context)) nodes.Assign.assigned_stmts = assign_assigned_stmts nodes.AugAssign.assigned_stmts = assign_assigned_stmts @@ -379,9 +382,11 @@ def excepthandler_assigned_stmts(self, node, context=None, asspath=None): if isinstance(assigned, nodes.ClassDef): assigned = bases.Instance(assigned) yield assigned - raise exceptions.DefaultStop(node=self, unknown=node, - assign_path=asspath, context=context) - + # Explicit StopIteration to return error information, see comment + # in raise_if_nothing_inferred. + raise StopIteration(dict(node=self, unknown=node, + assign_path=asspath, context=context)) + nodes.ExceptHandler.assigned_stmts = excepthandler_assigned_stmts @@ -479,8 +484,10 @@ def with_assigned_stmts(self, node, context=None, asspath=None): 'in {node!r}.', node=self, targets=node, assign_path=asspath, context=context)) yield obj - raise exceptions.DefaultStop(node=self, unknown=node, - assign_path=asspath, context=context) + # Explicit StopIteration to return error information, see comment + # in raise_if_nothing_inferred. + raise StopIteration(dict(node=self, unknown=node, + assign_path=asspath, context=context)) nodes.With.assigned_stmts = with_assigned_stmts |