mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-11 08:11:50 +08:00
added a method which returns all the stuff in an iterator
This commit is contained in:
10
dynamic.py
10
dynamic.py
@@ -93,6 +93,7 @@ def check_array_additions(array):
|
|||||||
current_module = array._array.parent_stmt.get_parent_until()
|
current_module = array._array.parent_stmt.get_parent_until()
|
||||||
return _check_array_additions(array, current_module, is_list)
|
return _check_array_additions(array, current_module, is_list)
|
||||||
|
|
||||||
|
|
||||||
@evaluate.memoize_default([])
|
@evaluate.memoize_default([])
|
||||||
def _check_array_additions(compare_array, module, is_list):
|
def _check_array_additions(compare_array, module, is_list):
|
||||||
"""
|
"""
|
||||||
@@ -157,10 +158,12 @@ def _check_array_additions(compare_array, module, is_list):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
for stmt in possible_stmts:
|
for stmt in possible_stmts:
|
||||||
result += check_calls(scan_array(stmt.get_assignment_calls(), n), n)
|
ass = stmt.get_assignment_calls()
|
||||||
|
result += check_calls(scan_array(ass, n), n)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def check_array_instances(instance):
|
def check_array_instances(instance):
|
||||||
ai = ArrayInstance(instance)
|
ai = ArrayInstance(instance)
|
||||||
return helpers.generate_param_array([ai])
|
return helpers.generate_param_array([ai])
|
||||||
@@ -188,8 +191,9 @@ class ArrayInstance(parsing.Base):
|
|||||||
if isinstance(temp, ArrayInstance):
|
if isinstance(temp, ArrayInstance):
|
||||||
items += temp.iter_content()
|
items += temp.iter_content()
|
||||||
continue
|
continue
|
||||||
items += array.get_index_types()
|
items += evaluate.handle_iterators([array])#array.get_index_types()
|
||||||
|
|
||||||
module = self.var_args.parent_stmt.get_parent_until()
|
module = self.var_args.parent_stmt.get_parent_until()
|
||||||
items += _check_array_additions(self.instance, module, str(self.instance.name) == 'list')
|
is_list = str(self.instance.name) == 'list'
|
||||||
|
items += _check_array_additions(self.instance, module, is_list)
|
||||||
return items
|
return items
|
||||||
|
|||||||
38
evaluate.py
38
evaluate.py
@@ -439,7 +439,7 @@ class Execution(Executable):
|
|||||||
# There maybe executions of executions.
|
# There maybe executions of executions.
|
||||||
stmts = [Instance(self.base, self.var_args)]
|
stmts = [Instance(self.base, self.var_args)]
|
||||||
elif isinstance(self.base, Generator):
|
elif isinstance(self.base, Generator):
|
||||||
return self.base.get_content()
|
return self.base.iter_content()
|
||||||
else:
|
else:
|
||||||
# Don't do this with exceptions, as usual, because some deeper
|
# Don't do this with exceptions, as usual, because some deeper
|
||||||
# exceptions could be catched - and I wouldn't know what happened.
|
# exceptions could be catched - and I wouldn't know what happened.
|
||||||
@@ -1055,6 +1055,42 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
return descriptor_check(remove_statements(filter_name(scope_generator)))
|
return descriptor_check(remove_statements(filter_name(scope_generator)))
|
||||||
|
|
||||||
|
|
||||||
|
def handle_iterators(inputs):
|
||||||
|
iterators = []
|
||||||
|
# Take the first statement (for has always only
|
||||||
|
# one, remember `in`). And follow it.
|
||||||
|
for it in inputs:
|
||||||
|
if isinstance(it, (Generator, Array, dynamic.ArrayInstance)):
|
||||||
|
iterators.append(it)
|
||||||
|
else:
|
||||||
|
if not hasattr(it, 'execute_subscope_by_name'):
|
||||||
|
debug.warning('iterator/for loop input wrong', it)
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
iterators += it.execute_subscope_by_name('__iter__')
|
||||||
|
except KeyError:
|
||||||
|
debug.warning('iterators: No __iter__ method found.')
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for gen in iterators:
|
||||||
|
if isinstance(gen, Array):
|
||||||
|
# Array is a little bit special, since this is an internal
|
||||||
|
# array, but there's also the list builtin, which is
|
||||||
|
# another thing.
|
||||||
|
result += gen.get_index_types()
|
||||||
|
elif isinstance(gen, Instance):
|
||||||
|
# __iter__ returned an instance.
|
||||||
|
name = '__next__' if is_py3k() else 'next'
|
||||||
|
try:
|
||||||
|
result += it.execute_subscope_by_name(name)
|
||||||
|
except KeyError:
|
||||||
|
debug.warning('Instance has no __next__ function', gen)
|
||||||
|
else:
|
||||||
|
# is a generator
|
||||||
|
result += gen.iter_content()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def assign_tuples(tup, results, seek_name):
|
def assign_tuples(tup, results, seek_name):
|
||||||
"""
|
"""
|
||||||
This is a normal assignment checker. In python functions and other things
|
This is a normal assignment checker. In python functions and other things
|
||||||
|
|||||||
@@ -202,3 +202,11 @@ lst.append({})
|
|||||||
|
|
||||||
#? dict() int() float() str()
|
#? dict() int() float() str()
|
||||||
lst[0]
|
lst[0]
|
||||||
|
|
||||||
|
# should work with tuple conversion, too.
|
||||||
|
#? dict() int() float() str()
|
||||||
|
tuple(lst)[0]
|
||||||
|
|
||||||
|
# but not with an iterator
|
||||||
|
#?
|
||||||
|
iter(lst)[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user