diff options
author | Nick Drozd <nicholasdrozd@gmail.com> | 2018-06-08 17:58:09 -0500 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-06-08 16:48:50 -0700 |
commit | 6cbfab46ba341e7e8fb8da1b6d9ce1cdd4a363c7 (patch) | |
tree | 714408be25f28619325f9151a050bf79c733aa2d /astroid/inference.py | |
parent | d1140ce68fba97ced9d2bfecead4f2a13427441b (diff) | |
download | astroid-git-6cbfab46ba341e7e8fb8da1b6d9ce1cdd4a363c7.tar.gz |
Convert to yield from
I tried this to see if it would improve performance. It didn't, but it
does look nicer, so we might as well keep it.
See also 5fd5aa81483e709cb5c464c7d4bb37c8c39f2afa
Diffstat (limited to 'astroid/inference.py')
-rw-r--r-- | astroid/inference.py | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/astroid/inference.py b/astroid/inference.py index 357e3091..fc63abcc 100644 --- a/astroid/inference.py +++ b/astroid/inference.py @@ -195,8 +195,7 @@ def infer_call(self, context=None): continue try: if hasattr(callee, 'infer_call_result'): - for inferred in callee.infer_call_result(self, callcontext, context_lookup): - yield inferred + yield from callee.infer_call_result(self, callcontext, context_lookup) except exceptions.InferenceError: ## XXX log error ? continue @@ -291,8 +290,7 @@ def infer_attribute(self, context=None): try: context.boundnode = owner - for obj in owner.igetattr(self.attrname, context): - yield obj + yield from owner.igetattr(self.attrname, context) context.boundnode = None except (exceptions.AttributeInferenceError, exceptions.InferenceError): context.boundnode = None @@ -379,8 +377,7 @@ def infer_subscript(self, context=None): if self is assigned or assigned is util.Uninferable: yield util.Uninferable return None - for inferred in assigned.infer(context): - yield inferred + yield from assigned.infer(context) # Explicit StopIteration to return error information, see comment # in raise_if_nothing_inferred. @@ -518,9 +515,8 @@ def _infer_unaryop(self, context=None): @decorators.path_wrapper def infer_unaryop(self, context=None): """Infer what an UnaryOp should return when evaluated.""" - for inferred in _filter_operation_errors(self, _infer_unaryop, context, - util.BadUnaryOperationMessage): - yield inferred + yield from _filter_operation_errors(self, _infer_unaryop, context, + util.BadUnaryOperationMessage) # Explicit StopIteration to return error information, see comment # in raise_if_nothing_inferred. return dict(node=self, context=context) @@ -732,9 +728,8 @@ def _infer_binop(self, context): return try: - for result in _infer_binary_operation(lhs, rhs, self, - context, _get_binop_flow): - yield result + yield from _infer_binary_operation( + lhs, rhs, self, context, _get_binop_flow) except exceptions._NonDeducibleTypeHierarchy: yield util.Uninferable @@ -768,8 +763,7 @@ def _infer_augassign(self, context=None): return try: - for result in _infer_binary_operation(lhs, rhs, self, context, _get_aug_flow): - yield result + yield from _infer_binary_operation(lhs, rhs, self, context, _get_aug_flow) except exceptions._NonDeducibleTypeHierarchy: yield util.Uninferable @@ -816,9 +810,7 @@ def infer_empty_node(self, context=None): yield util.Uninferable else: try: - for inferred in MANAGER.infer_ast_from_something(self.object, - context=context): - yield inferred + yield from MANAGER.infer_ast_from_something(self.object, context=context) except exceptions.AstroidError: yield util.Uninferable nodes.EmptyNode._infer = infer_empty_node |