예제 #1
0
 def iterate(self, contextualized_node=None, is_async=False):
     from jedi.inference.lazy_value import get_merged_lazy_value
     type_iters = [c.iterate(contextualized_node, is_async=is_async) for c in self._set]
     for lazy_values in zip_longest(*type_iters):
         yield get_merged_lazy_value(
             [l for l in lazy_values if l is not None]
         )
    def unpack(self, funcdef=None):
        named_args = []
        for star_count, el in unpack_arglist(self.argument_node):
            if star_count == 1:
                arrays = self.context.infer_node(el)
                iterators = [
                    _iterate_star_args(self.context, a, el, funcdef)
                    for a in arrays
                ]
                for values in list(zip_longest(*iterators)):
                    # TODO zip_longest yields None, that means this would raise
                    # an exception?
                    yield None, get_merged_lazy_value(
                        [v for v in values if v is not None])
            elif star_count == 2:
                arrays = self.context.infer_node(el)
                for dct in arrays:
                    for key, values in _star_star_dict(self.context, dct, el,
                                                       funcdef):
                        yield key, values
            else:
                if el.type == 'argument':
                    c = el.children
                    if len(c) == 3:  # Keyword argument.
                        named_args.append((
                            c[0].value,
                            LazyTreeValue(self.context, c[2]),
                        ))
                    else:  # Generator comprehension.
                        # Include the brackets with the parent.
                        sync_comp_for = el.children[1]
                        if sync_comp_for.type == 'comp_for':
                            sync_comp_for = sync_comp_for.children[1]
                        comp = iterable.GeneratorComprehension(
                            self._inference_state,
                            defining_context=self.context,
                            sync_comp_for_node=sync_comp_for,
                            entry_node=el.children[0],
                        )
                        yield None, LazyKnownValue(comp)
                else:
                    yield None, LazyTreeValue(self.context, el)

        # Reordering arguments is necessary, because star args sometimes appear
        # after named argument, but in the actual order it's prepended.
        for named_arg in named_args:
            yield named_arg