1
0
forked from VimPlug/jedi

get rid of is_list_comp boolean in favor of a direct check of ListComprehensionFlow

This commit is contained in:
Dave Halter
2014-06-09 20:19:31 +02:00
parent dd8e4341db
commit 0b926ca454
7 changed files with 17 additions and 21 deletions

View File

@@ -260,7 +260,7 @@ class Script(object):
if not is_completion:
# goto_definition returns definitions of its statements if the
# cursor is on the assignee. By changing the start_pos of our
# "pseud" statement, the Jedi evaluator can find the assignees.
# "pseudo" statement, the Jedi evaluator can find the assignees.
if user_stmt is not None:
eval_stmt.start_pos = user_stmt.end_pos
scopes = self._evaluator.eval_statement(eval_stmt)

View File

@@ -245,7 +245,7 @@ def save_parser(path, name, parser, pickling=True):
class ParserPickling(object):
version = 11
version = 12
"""
Version number (integer) for file system cache.

View File

@@ -83,7 +83,6 @@ from jedi.evaluate import stdlib
from jedi.evaluate import finder
from jedi.evaluate import compiled
from jedi.evaluate import precedence
from jedi.evaluate import helpers
class Evaluator(object):
@@ -379,19 +378,8 @@ def _evaluate_list_comprehension(lc, parent=None):
if isinstance(nested_lc, pr.ListComprehension):
# is nested LC
input = nested_lc.stmt
loop = ListComprehensionFlow(lc, input, parent)
loop = iterable.ListComprehensionFlow(lc, input, parent)
if isinstance(nested_lc, pr.ListComprehension):
loop = _evaluate_list_comprehension(nested_lc, loop)
return loop
class ListComprehensionFlow(pr.ForFlow):
"""Fake implementation to pretend being a ForFlow."""
def __init__(self, list_comprehension, input, parent):
lc = list_comprehension
sup = super(ListComprehensionFlow, self)
sup.__init__(helpers.FakeSubModule, [input], lc.parent.start_pos,
lc.middle, True)
self.parent = parent or lc.get_parent_until(pr.IsScope)
self.list_comprehension = list_comprehension

View File

@@ -316,8 +316,7 @@ class NameFinder(object):
return res_new + evaluator.eval_statement(param, seek_name=unicode(self.name_str))
def _handle_for_loops(self, loop):
# Take the first statement (for has always only
# one, remember `in`). And follow it.
# Take the first statement (for has always only one`in`).
if not loop.inputs:
return []
result = iterable.get_iterator_types(self._evaluator.eval_statement(loop.inputs[0]))
@@ -494,7 +493,7 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ
yield scope, _get_defined_names_for_position(scope, position, in_func_scope)
except StopIteration:
reraise(common.MultiLevelStopIteration, sys.exc_info()[2])
if scope.isinstance(pr.ForFlow) and scope.is_list_comp:
if scope.isinstance(iterable.ListComprehensionFlow):
# is a list comprehension
yield scope, scope.get_defined_names(is_internal_call=True)

View File

@@ -497,3 +497,13 @@ def create_indexes_or_slices(evaluator, index_array):
return (Slice(evaluator, start, stop, step),)
else:
return tuple(evaluator.process_precedence_element(prec))
class ListComprehensionFlow(pr.ForFlow):
"""Fake implementation to pretend being a ForFlow."""
def __init__(self, list_comprehension, input, parent):
lc = list_comprehension
sup = super(ListComprehensionFlow, self)
sup.__init__(helpers.FakeSubModule, [input], lc.parent.start_pos, lc.middle)
self.parent = parent or lc.get_parent_until(pr.IsScope)
self.list_comprehension = list_comprehension

View File

@@ -88,7 +88,7 @@ class _RecursionNode(object):
if not other:
return None
is_list_comp = lambda x: isinstance(x, pr.ForFlow) and x.is_list_comp
is_list_comp = lambda x: isinstance(x, iterable.ListComprehensionFlow)
return self.script == other.script \
and self.position == other.position \
and not is_list_comp(self.stmt.parent) \

View File

@@ -687,11 +687,10 @@ class ForFlow(Flow):
"""
Used for the for loop, because there are two statement parts.
"""
def __init__(self, module, inputs, start_pos, set_stmt, is_list_comp=False):
def __init__(self, module, inputs, start_pos, set_stmt):
super(ForFlow, self).__init__(module, 'for', inputs, start_pos)
self.set_stmt = set_stmt
self.is_list_comp = is_list_comp
if set_stmt is not None:
set_stmt.parent = self.use_as_parent