mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
functions don't return values anymore, if they are not executed
This commit is contained in:
57
evaluate.py
57
evaluate.py
@@ -324,7 +324,7 @@ def follow_statement(stmt, scope=None):
|
|||||||
parsing.Class, Instance)
|
parsing.Class, Instance)
|
||||||
call_list = stmt.get_assignment_calls()
|
call_list = stmt.get_assignment_calls()
|
||||||
debug.dbg('calls', call_list, call_list.values)
|
debug.dbg('calls', call_list, call_list.values)
|
||||||
return follow_call_list(scope, call_list)
|
return set(follow_call_list(scope, call_list))
|
||||||
|
|
||||||
|
|
||||||
def follow_call_list(scope, call_list):
|
def follow_call_list(scope, call_list):
|
||||||
@@ -382,40 +382,39 @@ def follow_paths(path, results):
|
|||||||
return results_new
|
return results_new
|
||||||
|
|
||||||
|
|
||||||
def follow_path(path, input):
|
def follow_path(path, scope):
|
||||||
"""
|
"""
|
||||||
Takes a generator and tries to complete the path.
|
Takes a generator and tries to complete the path.
|
||||||
"""
|
"""
|
||||||
# current is either an Array or a Scope
|
# current is either an Array or a Scope
|
||||||
current = next(path)
|
current = next(path)
|
||||||
debug.dbg('follow', current, input)
|
debug.dbg('follow', current, scope)
|
||||||
|
|
||||||
def filter_result(scope):
|
result = []
|
||||||
result = []
|
if isinstance(current, parsing.Array):
|
||||||
if isinstance(current, parsing.Array):
|
# this must be an execution, either () or []
|
||||||
# this must be an execution, either () or []
|
if current.type == parsing.Array.LIST:
|
||||||
if current.type == parsing.Array.LIST:
|
result = scope.get_index_types(current)
|
||||||
result = scope.get_index_types(current)
|
elif current.type not in [parsing.Array.DICT]:
|
||||||
elif current.type not in [parsing.Array.DICT]:
|
# scope must be a class or func - make an instance or execution
|
||||||
# scope must be a class or func - make an instance or execution
|
debug.dbg('befexec', scope)
|
||||||
debug.dbg('befexec', scope)
|
exe = Execution(scope, current)
|
||||||
exe = Execution(scope, current)
|
result = strip_imports(exe.get_return_types())
|
||||||
result = strip_imports(exe.get_return_types())
|
debug.dbg('exec', result)
|
||||||
debug.dbg('exec', result)
|
#except AttributeError:
|
||||||
#except AttributeError:
|
# debug.dbg('cannot execute:', scope)
|
||||||
# debug.dbg('cannot execute:', scope)
|
|
||||||
else:
|
|
||||||
# curly braces are not allowed, because they make no sense
|
|
||||||
debug.warning('strange function call with {}', current, scope)
|
|
||||||
else:
|
else:
|
||||||
if isinstance(scope, parsing.Function):
|
# curly braces are not allowed, because they make no sense
|
||||||
# TODO check default function methods and return them
|
debug.warning('strange function call with {}', current, scope)
|
||||||
result = []
|
else:
|
||||||
else:
|
if isinstance(scope, parsing.Function):
|
||||||
# TODO check magic class methods and return them also
|
# TODO this is never reached, just remove it?
|
||||||
result = strip_imports(get_scopes_for_name(scope, current))
|
# TODO check default function methods and return them
|
||||||
return result
|
result = []
|
||||||
return follow_paths(path, filter_result(input))
|
else:
|
||||||
|
# TODO check magic class methods and return them also
|
||||||
|
result = strip_imports(get_scopes_for_name(scope, current))
|
||||||
|
return follow_paths(path, result)
|
||||||
|
|
||||||
|
|
||||||
def follow_import(_import):
|
def follow_import(_import):
|
||||||
@@ -456,4 +455,4 @@ def remove_star_imports(scope):
|
|||||||
modules += new
|
modules += new
|
||||||
|
|
||||||
# filter duplicate modules
|
# filter duplicate modules
|
||||||
return list(set(modules))
|
return set(modules)
|
||||||
|
|||||||
16
functions.py
16
functions.py
@@ -188,6 +188,9 @@ def complete(source, row, column, source_path):
|
|||||||
stmt = r.top.statements[0]
|
stmt = r.top.statements[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
completions = evaluate.get_names_for_scope(scope)
|
completions = evaluate.get_names_for_scope(scope)
|
||||||
|
#for c in completions:
|
||||||
|
# if isinstance(, parsing.Function):
|
||||||
|
# print c.parent
|
||||||
else:
|
else:
|
||||||
stmt.parent = scope
|
stmt.parent = scope
|
||||||
scopes = evaluate.follow_statement(stmt, scope=scope)
|
scopes = evaluate.follow_statement(stmt, scope=scope)
|
||||||
@@ -195,16 +198,17 @@ def complete(source, row, column, source_path):
|
|||||||
completions = []
|
completions = []
|
||||||
debug.dbg('possible scopes', scopes)
|
debug.dbg('possible scopes', scopes)
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
completions += s.get_defined_names()
|
# TODO is this reall the right way, just ignore the functions?
|
||||||
|
if not isinstance(s, parsing.Function):
|
||||||
|
completions += s.get_defined_names()
|
||||||
|
|
||||||
completions = list(set(completions))
|
completions = [c for c in completions
|
||||||
|
|
||||||
needs_dot = not dot and path
|
|
||||||
completions = [Completion(c, needs_dot, len(like)) for c in completions
|
|
||||||
if c.names[-1].lower().startswith(like.lower())]
|
if c.names[-1].lower().startswith(like.lower())]
|
||||||
|
|
||||||
_clear_caches()
|
_clear_caches()
|
||||||
return completions
|
|
||||||
|
needs_dot = not dot and path
|
||||||
|
return [Completion(c, needs_dot, len(like)) for c in set(completions)]
|
||||||
|
|
||||||
|
|
||||||
def set_debug_function(func_cb):
|
def set_debug_function(func_cb):
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ def array(first_param):
|
|||||||
|
|
||||||
#? []
|
#? []
|
||||||
array.first_param
|
array.first_param
|
||||||
|
#? []
|
||||||
|
array.first_param.
|
||||||
|
func = array
|
||||||
|
#? []
|
||||||
|
func.first_param
|
||||||
|
|
||||||
#? ['append']
|
#? ['append']
|
||||||
array().append
|
array().append
|
||||||
|
|||||||
Reference in New Issue
Block a user