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 | 336760405946c1ee0c8f1dc1e194b69ae73ed857 (patch) | |
tree | c5beb7e32d903a7bae271fa645bcdcc0b072a9fa /astroid/protocols.py | |
parent | 2a0ae68ad53ca60b7a31124ea2bef5c219d4e03b (diff) | |
download | astroid-336760405946c1ee0c8f1dc1e194b69ae73ed857.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 2e01124..5809e4a 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 |