1
0
forked from VimPlug/jedi

fixed some exceptions -> mostly related to used_names access of module

This commit is contained in:
David Halter
2012-09-27 09:37:23 +02:00
parent 908d019390
commit 1ae2a36838
2 changed files with 24 additions and 12 deletions

View File

@@ -118,6 +118,7 @@ def search_params(param):
return [] return []
for stmt in possible_stmts: for stmt in possible_stmts:
if not isinstance(stmt, parsing.Import):
evaluate.follow_statement(stmt) evaluate.follow_statement(stmt)
return listener.param_possibilities return listener.param_possibilities
@@ -126,7 +127,6 @@ def search_params(param):
for p in params: for p in params:
if str(p) == param_name: if str(p) == param_name:
result += evaluate.follow_statement(p.parent()) result += evaluate.follow_statement(p.parent())
return result return result
func = param.get_parent_until(parsing.Function) func = param.get_parent_until(parsing.Function)
@@ -147,6 +147,8 @@ def search_params(param):
listener = ParamListener() listener = ParamListener()
func.listeners.add(listener) func.listeners.add(listener)
result = []
# This is like backtracking: Get the first possible result.
for mod in get_directory_modules_for_name([current_module], func_name): for mod in get_directory_modules_for_name([current_module], func_name):
result = get_params_for_module(mod) result = get_params_for_module(mod)
if result: if result:

View File

@@ -422,7 +422,7 @@ class Flow(Scope):
else: else:
self.set_vars = set_vars self.set_vars = set_vars
for s in self.set_vars: for s in self.set_vars:
s.parent = weakref.ref(self) s.parent().parent = weakref.ref(self)
@property @property
def parent(self): def parent(self):
@@ -435,17 +435,11 @@ class Flow(Scope):
self.next.parent = value self.next.parent = value
def get_code(self, first_indent=False, indention=" "): def get_code(self, first_indent=False, indention=" "):
if self.set_vars:
vars = ",".join(map(lambda x: x.get_code(), self.set_vars))
vars += ' in '
else:
vars = ''
stmts = [] stmts = []
for s in self.inits: for s in self.inits:
stmts.append(s.get_code(new_line=False)) stmts.append(s.get_code(new_line=False))
stmt = ', '.join(stmts) stmt = ', '.join(stmts)
str = "%s %s%s:\n" % (self.command, vars, stmt) str = "%s %s:\n" % (self.command, vars, stmt)
str += super(Flow, self).get_code(True, indention) str += super(Flow, self).get_code(True, indention)
if self.next: if self.next:
str += self.next.get_code() str += self.next.get_code()
@@ -496,6 +490,15 @@ class ForFlow(Flow):
self.set_stmt = set_stmt self.set_stmt = set_stmt
self.is_list_comp = is_list_comp self.is_list_comp = is_list_comp
def get_code(self, first_indent=False, indention=" " * 4):
vars = ",".join(x.get_code() for x in self.set_vars)
stmts = []
for s in self.inits:
stmts.append(s.get_code(new_line=False))
stmt = ', '.join(stmts)
s = "for %s in %s:\n" % (vars, stmt)
return s + super(Flow, self).get_code(True, indention)
class Import(Simple): class Import(Simple):
""" """
@@ -1436,6 +1439,8 @@ class PyFuzzyParser(object):
if tok != 'in' or middle is None: if tok != 'in' or middle is None:
if middle is None: if middle is None:
level -= 1 level -= 1
else:
middle.parent = weakref.ref(self.scope)
debug.warning('list comprehension formatting @%s' % debug.warning('list comprehension formatting @%s' %
self.start_pos[0]) self.start_pos[0])
continue continue
@@ -1444,8 +1449,12 @@ class PyFuzzyParser(object):
in_clause, tok = self._parse_statement(added_breaks=b, in_clause, tok = self._parse_statement(added_breaks=b,
list_comp=True) list_comp=True)
if tok not in b or in_clause is None: if tok not in b or in_clause is None:
middle.parent = weakref.ref(self.scope)
if in_clause is None: if in_clause is None:
self.gen.push_back(self._current_full) self.gen.push_back(self._current_full)
else:
in_clause.parent = weakref.ref(self.scope)
in_clause.parent = weakref.ref(self.scope)
debug.warning('list comprehension in_clause %s@%s' debug.warning('list comprehension in_clause %s@%s'
% (tok, self.start_pos[0])) % (tok, self.start_pos[0]))
continue continue
@@ -1680,8 +1689,7 @@ class PyFuzzyParser(object):
if tok == 'in': if tok == 'in':
statement, tok = self._parse_statement() statement, tok = self._parse_statement()
if tok == ':': if tok == ':':
f = ForFlow([statement], first_pos, f = ForFlow([statement], first_pos, set_stmt)
set_stmt)
self.scope = self.scope.add_statement(f) self.scope = self.scope.add_statement(f)
elif tok in ['if', 'while', 'try', 'with'] + extended_flow: elif tok in ['if', 'while', 'try', 'with'] + extended_flow:
@@ -1721,6 +1729,8 @@ class PyFuzzyParser(object):
s = self.scope.add_statement(f) s = self.scope.add_statement(f)
self.scope = s self.scope = s
else: else:
for i in inits:
i.parent = weakref.ref(self.scope)
debug.warning('syntax err, flow started @%s', debug.warning('syntax err, flow started @%s',
self.start_pos[0]) self.start_pos[0])
# globals # globals