fix problems with unnecessary brackets and following executions, which fixes also the last remaining lambda problem

This commit is contained in:
David Halter
2012-12-24 10:47:11 +01:00
parent 3f95d33f4d
commit e647e09f0c
3 changed files with 18 additions and 10 deletions

View File

@@ -1328,7 +1328,7 @@ def follow_statement(stmt, seek_name=None):
return set(result) return set(result)
def follow_call_list(call_list): def follow_call_list(call_list, follow_array=False):
""" """
The call_list has a special structure. The call_list has a special structure.
This can be either `parsing.Array` or `list of list`. This can be either `parsing.Array` or `list of list`.
@@ -1364,7 +1364,7 @@ def follow_call_list(call_list):
calls_iterator = iter(calls) calls_iterator = iter(calls)
for call in calls_iterator: for call in calls_iterator:
if parsing.Array.is_type(call, parsing.Array.NOARRAY): if parsing.Array.is_type(call, parsing.Array.NOARRAY):
result += follow_call_list(call) result += follow_call_list(call, follow_array=True)
elif isinstance(call, parsing.ListComprehension): elif isinstance(call, parsing.ListComprehension):
loop = evaluate_list_comprehension(call) loop = evaluate_list_comprehension(call)
stmt = copy.copy(call.stmt) stmt = copy.copy(call.stmt)
@@ -1401,6 +1401,14 @@ def follow_call_list(call_list):
and str(r.name) == 'str']: and str(r.name) == 'str']:
# if it is an iterable, ignore * operations # if it is an iterable, ignore * operations
next(calls_iterator) next(calls_iterator)
if follow_array and isinstance(call_list, parsing.Array):
# call_list can also be a two dimensional array
call_path = call_list.generate_call_path()
next(call_path, None) # the first one has been used already
call_scope = call_list.parent_stmt
position = call_list.start_pos
result = follow_paths(call_path, result, call_scope, position=position)
return set(result) return set(result)
@@ -1419,7 +1427,11 @@ def follow_call_path(path, scope, position):
if isinstance(current, parsing.Array): if isinstance(current, parsing.Array):
result = [Array(current)] result = [Array(current)]
else: else:
if not isinstance(current, parsing.NamePart): if isinstance(current, parsing.NamePart):
# This is the first global lookup.
scopes = get_scopes_for_name(scope, current, position=position,
search_global=True)
else:
if current.type in (parsing.Call.STRING, parsing.Call.NUMBER): if current.type in (parsing.Call.STRING, parsing.Call.NUMBER):
t = type(current.name).__name__ t = type(current.name).__name__
scopes = get_scopes_for_name(builtin.Builtin.scope, t) scopes = get_scopes_for_name(builtin.Builtin.scope, t)
@@ -1429,10 +1441,6 @@ def follow_call_path(path, scope, position):
# Make instances of those number/string objects. # Make instances of those number/string objects.
arr = helpers.generate_param_array([current.name]) arr = helpers.generate_param_array([current.name])
scopes = [Instance(s, arr) for s in scopes] scopes = [Instance(s, arr) for s in scopes]
else:
# This is the first global lookup.
scopes = get_scopes_for_name(scope, current, position=position,
search_global=True)
result = imports.strip_imports(scopes) result = imports.strip_imports(scopes)
return follow_paths(path, result, scope, position=position) return follow_paths(path, result, scope, position=position)
@@ -1467,7 +1475,7 @@ def follow_path(path, scope, call_scope, position=None):
`follow_path` is only responsible for completing `.bar.baz`, the rest is `follow_path` is only responsible for completing `.bar.baz`, the rest is
done in the `follow_call` function. done in the `follow_call` function.
""" """
# Current is either an Array or a Scope. # current is either an Array or a Scope.
try: try:
current = next(path) current = next(path)
except StopIteration: except StopIteration:

View File

@@ -1322,7 +1322,6 @@ class PyFuzzyParser(object):
n = Name(self.module, names, first_pos, self.end_pos) if names \ n = Name(self.module, names, first_pos, self.end_pos) if names \
else None else None
#if self.module.path != '__builtin__': print n
return n, token_type, tok return n, token_type, tok
def _parseimportlist(self): def _parseimportlist(self):
@@ -1558,7 +1557,6 @@ class PyFuzzyParser(object):
lambd.returns.append(ret) lambd.returns.append(ret)
lambd.parent = self.scope lambd.parent = self.scope
lambd.end_pos = self.end_pos lambd.end_pos = self.end_pos
#print lambd, added_breaks, ret, param
tok_list[-1] = lambd tok_list[-1] = lambd
continue continue
elif token_type == tokenize.NAME: elif token_type == tokenize.NAME:

View File

@@ -125,6 +125,8 @@ def a(): return ''
(a)().replace() (a)().replace()
#? int() #? int()
(tuple).index() (tuple).index()
#? int()
(tuple)().index()
# ----------------- # -----------------