示例#1
0
 def py__iter__(self, contextualized_node=None):
     if self._is_homogenous():
         yield LazyKnownValues(self._get_getitem_values(0).execute_annotation())
     else:
         if isinstance(self._index_value, SequenceLiteralValue):
             for i in range(self._index_value.py__len__()):
                 yield LazyKnownValues(self._get_getitem_values(i).execute_annotation())
示例#2
0
 def py__iter__(self, contextualized_node=None):
     if self._is_homogenous():
         yield LazyKnownValues(
             self._generics_manager.get_index_and_execute(0))
     else:
         for v in self._generics_manager.to_tuple():
             yield LazyKnownValues(v.execute_annotation())
示例#3
0
    def _imitate_items(self, arguments):
        lazy_values = [
            LazyKnownValue(
                FakeTuple(self.inference_state,
                          [LazyKnownValues(key),
                           LazyKnownValues(value)]))
            for key, value in self._iterate()
        ]

        return ValueSet([FakeList(self.inference_state, lazy_values)])
示例#4
0
 def py__next__(self, contextualized_node=None):
     name = u'__next__'
     next_slot_names = self.get_function_slot_names(name)
     if next_slot_names:
         yield LazyKnownValues(self.execute_function_slots(next_slot_names))
     else:
         debug.warning('Instance has no __next__ function in %s.', self)
示例#5
0
 def py__next__(self, contextualized_node=None):
     # `__next__` logic.
     if self.inference_state.environment.version_info.major == 2:
         name = u'next'
     else:
         name = u'__next__'
     next_slot_names = self.get_function_slot_names(name)
     if next_slot_names:
         yield LazyKnownValues(self.execute_function_slots(next_slot_names))
     else:
         debug.warning('Instance has no __next__ function in %s.', self)
示例#6
0
 def py__iter__(self, contextualized_node=None):
     """
     While values returns the possible values for any array field, this
     function returns the value for a certain index.
     """
     # Get keys.
     types = NO_VALUES
     for k, _ in self.get_tree_entries():
         types |= self._defining_context.infer_node(k)
     # We don't know which dict index comes first, therefore always
     # yield all the types.
     for _ in types:
         yield LazyKnownValues(types)
示例#7
0
文件: klass.py 项目: h0t0sh0/jedi
    def py__bases__(self):
        args = self._get_bases_arguments()
        if args is not None:
            lst = [value for key, value in args.unpack() if key is None]
            if lst:
                return lst

        if self.py__name__() == 'object' \
                and self.parent_context.is_builtins_module():
            return []
        return [LazyKnownValues(
            self.inference_state.builtins_module.py__getattribute__('object')
        )]
示例#8
0
    def get_yield_lazy_values(self, is_async=False):
        # TODO: if is_async, wrap yield statements in Awaitable/async_generator_asend
        for_parents = [
            (y,
             tree.search_ancestor(y, 'for_stmt', 'funcdef', 'while_stmt',
                                  'if_stmt'))
            for y in get_yield_exprs(self.inference_state, self.tree_node)
        ]

        # Calculate if the yields are placed within the same for loop.
        yields_order = []
        last_for_stmt = None
        for yield_, for_stmt in for_parents:
            # For really simple for loops we can predict the order. Otherwise
            # we just ignore it.
            parent = for_stmt.parent
            if parent.type == 'suite':
                parent = parent.parent
            if for_stmt.type == 'for_stmt' and parent == self.tree_node \
                    and parser_utils.for_stmt_defines_one_name(for_stmt):  # Simplicity for now.
                if for_stmt == last_for_stmt:
                    yields_order[-1][1].append(yield_)
                else:
                    yields_order.append((for_stmt, [yield_]))
            elif for_stmt == self.tree_node:
                yields_order.append((None, [yield_]))
            else:
                types = self.get_return_values(check_yields=True)
                if types:
                    yield LazyKnownValues(types)
                return
            last_for_stmt = for_stmt

        for for_stmt, yields in yields_order:
            if for_stmt is None:
                # No for_stmt, just normal yields.
                for yield_ in yields:
                    for result in self._get_yield_lazy_value(yield_):
                        yield result
            else:
                input_node = for_stmt.get_testlist()
                cn = ContextualizedNode(self, input_node)
                ordered = cn.infer().iterate(cn)
                ordered = list(ordered)
                for lazy_value in ordered:
                    dct = {str(for_stmt.children[1].value): lazy_value.infer()}
                    with self.predefine_names(for_stmt, dct):
                        for yield_in_same_for_stmt in yields:
                            for result in self._get_yield_lazy_value(
                                    yield_in_same_for_stmt):
                                yield result
 def iterate(self, contextualized_node=None, is_async=False):
     debug.dbg('iterate %s', self)
     if is_async:
         from jedi.inference.lazy_value import LazyKnownValues
         # TODO if no __aiter__ values are there, error should be:
         # TypeError: 'async for' requires an object with __aiter__ method, got int
         return iter([
             LazyKnownValues(
                 self.py__getattribute__('__aiter__').execute_with_values(
                 ).py__getattribute__('__anext__').execute_with_values(
                 ).py__getattribute__('__await__').execute_with_values().
                 py__stop_iteration_returns())  # noqa
         ])
     return self.py__iter__(contextualized_node)
示例#10
0
 def py__call__(self, item_value_set):
     value_set = NO_VALUES
     for args_value in self._args_value_set:
         lazy_values = list(args_value.py__iter__())
         if len(lazy_values) == 1:
             # TODO we need to add the contextualized value.
             value_set |= item_value_set.get_item(lazy_values[0].infer(), None)
         else:
             value_set |= ValueSet([iterable.FakeList(
                 self._wrapped_value.inference_state,
                 [
                     LazyKnownValues(item_value_set.get_item(lazy_value.infer(), None))
                     for lazy_value in lazy_values
                 ],
             )])
     return value_set
示例#11
0
 def iterate():
     for generator in self.execute_function_slots(iter_slot_names):
         if generator.is_instance() and not generator.is_compiled():
             # `__next__` logic.
             if self.inference_state.environment.version_info.major == 2:
                 name = u'next'
             else:
                 name = u'__next__'
             next_slot_names = generator.get_function_slot_names(name)
             if next_slot_names:
                 yield LazyKnownValues(
                     generator.execute_function_slots(next_slot_names)
                 )
             else:
                 debug.warning('Instance has no __next__ function in %s.', generator)
         else:
             for lazy_value in generator.py__iter__():
                 yield lazy_value
示例#12
0
def _execute_array_values(inference_state, array):
    """
    Tuples indicate that there's not just one return value, but the listed
    ones.  `(str, int)` means that it returns a tuple with both types.
    """
    from jedi.inference.value.iterable import SequenceLiteralValue, FakeTuple, FakeList
    if isinstance(array, SequenceLiteralValue) and array.array_type in ('tuple', 'list'):
        values = []
        for lazy_value in array.py__iter__():
            objects = ValueSet.from_sets(
                _execute_array_values(inference_state, typ)
                for typ in lazy_value.infer()
            )
            values.append(LazyKnownValues(objects))
        cls = FakeTuple if array.array_type == 'tuple' else FakeList
        return {cls(inference_state, values)}
    else:
        return array.execute_annotation()
示例#13
0
 def py__bases__(self):
     return [
         LazyKnownValues(
             self.inference_state.builtins_module.py__getattribute__(
                 'object'))
     ]
示例#14
0
 def py__iter__(self, contextualized_node=None):
     yield from self._wrapped_value.py__iter__(contextualized_node)
     yield LazyKnownValues(self._assigned_values)
示例#15
0
 def py__iter__(self, contextualized_node=None):
     for lazy_context in self._wrapped_value.py__iter__(
             contextualized_node):
         yield lazy_context
     yield LazyKnownValues(self._assigned_values)
示例#16
0
 def _values(self, arguments):
     return ValueSet([
         FakeTuple(self.inference_state,
                   [LazyKnownValues(self._dict_values())])
     ])
示例#17
0
 def _imitate_values(self, arguments):
     lazy_value = LazyKnownValues(self._dict_values())
     return ValueSet([FakeList(self.inference_state, [lazy_value])])
示例#18
0
 def py__iter__(self):
     for lazy_context in self._wrapped_value.py__iter__():
         yield lazy_context
     yield LazyKnownValues(self._assigned_values)
示例#19
0
 def py__iter__(self, contextualized_node=None):
     for keys, values in self._iterate():
         yield LazyKnownValues(keys)
示例#20
0
 def py__iter__(self, contextualized_node=None):
     for set_ in self._iterate():
         yield LazyKnownValues(set_)
 def unpack(self, funcdef=None):
     for values in self._values_list:
         yield None, LazyKnownValues(values)