diff options
-rw-r--r-- | astroid/bases.py | 3 | ||||
-rw-r--r-- | astroid/inference.py | 26 | ||||
-rw-r--r-- | astroid/node_classes.py | 28 | ||||
-rw-r--r-- | astroid/protocols.py | 25 | ||||
-rw-r--r-- | astroid/scoped_nodes.py | 25 |
5 files changed, 36 insertions, 71 deletions
diff --git a/astroid/bases.py b/astroid/bases.py index 67783ad5..f40c825a 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -204,8 +204,7 @@ class BaseInstance(Proxy): for attr in attrs: if isinstance(attr, UnboundMethod): if _is_property(attr): - for inferred in attr.infer_call_result(self, context): - yield inferred + yield from attr.infer_call_result(self, context) else: yield BoundMethod(attr, self) elif hasattr(attr, 'name') and attr.name == '<lambda>': 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 diff --git a/astroid/node_classes.py b/astroid/node_classes.py index 5ab03c35..071631be 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -43,8 +43,7 @@ def unpack_infer(stmt, context=None): if elt is util.Uninferable: yield elt continue - for inferred_elt in unpack_infer(elt, context): - yield inferred_elt + yield from unpack_infer(elt, context) # Explicit StopIteration to return error information, see comment # in raise_if_nothing_inferred. return dict(node=stmt, context=context) @@ -60,8 +59,8 @@ def unpack_infer(stmt, context=None): if inferred is util.Uninferable: yield inferred else: - for inf_inf in unpack_infer(inferred, context): - yield inf_inf + yield from unpack_infer(inferred, context) + return dict(node=stmt, context=context) @@ -368,8 +367,7 @@ class NodeNG(object): if attr is None: continue if isinstance(attr, (list, tuple)): - for elt in attr: - yield elt + yield from attr else: yield attr @@ -633,24 +631,21 @@ class NodeNG(object): if skip_klass is None: for child_node in self.get_children(): - for matching in child_node.nodes_of_class(klass, skip_klass): - yield matching + yield from child_node.nodes_of_class(klass, skip_klass) return for child_node in self.get_children(): if isinstance(child_node, skip_klass): continue - for matching in child_node.nodes_of_class(klass, skip_klass): - yield matching + yield from child_node.nodes_of_class(klass, skip_klass) def _get_assign_nodes(self): yield from () def _get_name_nodes(self): for child_node in self.get_children(): - for matching in child_node._get_name_nodes(): - yield matching + yield from child_node._get_name_nodes() def _get_return_nodes_skip_functions(self): yield from () @@ -1289,8 +1284,7 @@ class Name(LookupMixIn, NodeNG): yield self for child_node in self.get_children(): - for matching in child_node._get_name_nodes(): - yield matching + yield from child_node._get_name_nodes() class Arguments(mixins.AssignTypeMixin, NodeNG): @@ -3774,8 +3768,7 @@ class Slice(NodeNG): elif attrname == 'step': yield self._wrap_attribute(self.step) else: - for value in self.getattr(attrname, context=context): - yield value + yield from self.getattr(attrname, context=context) def getattr(self, attrname, context=None): return self._proxied.getattr(attrname, context) @@ -4296,8 +4289,7 @@ class With(mixins.MultiLineBlockMixin, mixins.BlockRangeMixIn, yield expr if var: yield var - for elt in self.body: - yield elt + yield from self.body class AsyncWith(With): diff --git a/astroid/protocols.py b/astroid/protocols.py index 4ff46fbb..18eb2ade 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -236,9 +236,7 @@ def _resolve_looppart(parts, asspath, context): # we are not yet on the last part of the path # search on each possibly inferred value try: - for inferred in _resolve_looppart(assigned.infer(context), - asspath, context): - yield inferred + yield from _resolve_looppart(assigned.infer(context), asspath, context) except exceptions.InferenceError: break @@ -251,12 +249,9 @@ def for_assigned_stmts(self, node=None, context=None, asspath=None): if asspath is None: for lst in self.iter.infer(context): if isinstance(lst, (nodes.Tuple, nodes.List)): - for item in lst.elts: - yield item + yield from lst.elts else: - for inferred in _resolve_looppart(self.iter.infer(context), - asspath, context): - yield inferred + yield from _resolve_looppart(self.iter.infer(context), asspath, context) # Explicit StopIteration to return error information, see comment # in raise_if_nothing_inferred. return dict(node=self, unknown=node, @@ -330,8 +325,7 @@ def _arguments_infer_argname(self, name, context): # we can't guess given argument value try: context = contextmod.copy_context(context) - for inferred in self.default_value(name).infer(context): - yield inferred + yield from self.default_value(name).infer(context) yield util.Uninferable except exceptions.NoDefault: yield util.Uninferable @@ -355,8 +349,8 @@ def assign_assigned_stmts(self, node=None, context=None, asspath=None): if not asspath: yield self.value return None - for inferred in _resolve_asspart(self.value.infer(context), asspath, context): - yield inferred + yield from _resolve_asspart(self.value.infer(context), asspath, context) + # Explicit StopIteration to return error information, see comment # in raise_if_nothing_inferred. return dict(node=self, unknown=node, @@ -398,9 +392,7 @@ def _resolve_asspart(parts, asspath, context): # we are not yet on the last part of the path search on each # possibly inferred value try: - for inferred in _resolve_asspart(assigned.infer(context), - asspath, context): - yield inferred + yield from _resolve_asspart(assigned.infer(context), asspath, context) except exceptions.InferenceError: return @@ -459,8 +451,7 @@ def _infer_context_manager(self, mgr, context): const.lineno = yield_point.lineno yield const else: - for inferred in yield_point.value.infer(context=context): - yield inferred + yield from yield_point.value.infer(context=context) elif isinstance(inferred, bases.Instance): try: enter = next(inferred.igetattr('__enter__', context=context)) diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index 06b11bc4..41d18597 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -704,8 +704,7 @@ class Module(LocalsDictNodeNG): return True def get_children(self): - for elt in self.body: - yield elt + yield from self.body class ComprehensionScope(LocalsDictNodeNG): @@ -1609,8 +1608,7 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda): yield node_classes.Const(None) else: try: - for inferred in returnnode.value.infer(context): - yield inferred + yield from returnnode.value.infer(context) except exceptions.InferenceError: yield util.Uninferable @@ -1632,8 +1630,7 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda): if self.returns is not None: yield self.returns - for elt in self.body: - yield elt + yield from self.body class AsyncFunctionDef(FunctionDef): @@ -2337,8 +2334,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, if bases._is_property(attr): # TODO(cpopa): don't use a private API. - for inferred in attr.infer_call_result(self, context): - yield inferred + yield from attr.infer_call_result(self, context) continue if attr.type == 'classmethod': # If the method is a classmethod, then it will @@ -2634,8 +2630,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, except NotImplementedError: continue if cls_slots is not None: - for slot in cls_slots: - yield slot + yield from cls_slots else: yield None @@ -2682,8 +2677,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, if not baseobj.hide: yield baseobj else: - for base in baseobj.bases: - yield base + yield from baseobj.bases def _compute_mro(self, context=None): inferred_bases = list(self._inferred_bases(context=context)) @@ -2739,11 +2733,8 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, if self.decorators is not None: yield self.decorators - for elt in self.bases: - yield elt - - for elt in self.body: - yield elt + yield from self.bases + yield from self.body def _get_assign_nodes(self): for child_node in self.body: |