mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 10:37:52 +08:00
Trying to fix issues with for loops and += operators.
This commit is contained in:
@@ -122,7 +122,7 @@ class Evaluator(object):
|
|||||||
return f.find(scopes, search_global)
|
return f.find(scopes, search_global)
|
||||||
|
|
||||||
#@memoize_default(default=[], evaluator_is_first_arg=True)
|
#@memoize_default(default=[], evaluator_is_first_arg=True)
|
||||||
@recursion.recursion_decorator
|
#@recursion.recursion_decorator
|
||||||
@debug.increase_indent
|
@debug.increase_indent
|
||||||
def eval_statement(self, stmt, seek_name=None):
|
def eval_statement(self, stmt, seek_name=None):
|
||||||
"""
|
"""
|
||||||
@@ -149,15 +149,22 @@ class Evaluator(object):
|
|||||||
left = self.find_types(parent, name, stmt.start_pos, search_global=True)
|
left = self.find_types(parent, name, stmt.start_pos, search_global=True)
|
||||||
|
|
||||||
for_stmt = stmt.get_parent_until(tree.ForStmt)
|
for_stmt = stmt.get_parent_until(tree.ForStmt)
|
||||||
if isinstance(for_stmt, tree.ForStmt):
|
if isinstance(for_stmt, tree.ForStmt) and types \
|
||||||
|
and isinstance(for_stmt.children[1], tree.Name) \
|
||||||
|
and self.predefined_if_name_dict_dict.get(for_stmt) is None:
|
||||||
# Iterate through result and add the values, that's possible
|
# Iterate through result and add the values, that's possible
|
||||||
# only in for loops without clutter, because they are
|
# only in for loops without clutter, because they are
|
||||||
# predictable.
|
# predictable. Also only do it, if the variable is not a tuple.
|
||||||
for_iterable = self.eval_element(for_stmt.children[3])
|
for_iterable = self.eval_element(for_stmt.children[3])
|
||||||
ordered = iterable.ordered_elements_of_iterable(self, for_iterable, types)
|
ordered = iterable.ordered_elements_of_iterable(self, for_iterable, types)
|
||||||
|
|
||||||
for index_types in ordered:
|
for index_types in ordered:
|
||||||
left = precedence.calculate(self, left, operator, index_types)
|
dct = {for_stmt.children[1]: index_types}
|
||||||
|
self.predefined_if_name_dict_dict[for_stmt] = dct
|
||||||
|
t = self.eval_statement(stmt)
|
||||||
|
left = precedence.calculate(self, left, operator, t)
|
||||||
types = left
|
types = left
|
||||||
|
del self.predefined_if_name_dict_dict[for_stmt]
|
||||||
else:
|
else:
|
||||||
types = precedence.calculate(self, left, operator, types)
|
types = precedence.calculate(self, left, operator, types)
|
||||||
debug.dbg('eval_statement result %s', types)
|
debug.dbg('eval_statement result %s', types)
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ class NameFinder(object):
|
|||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
if isinstance(scope, tree.IsScope) or scope is None:
|
if isinstance(scope, tree.IsScope) or scope is None:
|
||||||
break
|
break
|
||||||
elif isinstance(scope, tree.IfStmt):
|
elif isinstance(scope, (tree.IfStmt, tree.ForStmt)):
|
||||||
try:
|
try:
|
||||||
name_dict = self._evaluator.predefined_if_name_dict_dict[scope]
|
name_dict = self._evaluator.predefined_if_name_dict_dict[scope]
|
||||||
types = set(name_dict[str(self.name_str)])
|
types = set(name_dict[str(self.name_str)])
|
||||||
|
|||||||
Reference in New Issue
Block a user