mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Fix dynamic param checking
This commit is contained in:
@@ -128,11 +128,8 @@ def _search_function_executions(inference_state, module_context, funcdef, string
|
|||||||
|
|
||||||
found_executions = False
|
found_executions = False
|
||||||
i = 0
|
i = 0
|
||||||
for for_mod_value in imports.get_modules_containing_name(
|
for for_mod_context in imports.get_module_contexts_containing_name(
|
||||||
inference_state, [module_context], string_name):
|
inference_state, [module_context], string_name):
|
||||||
if not isinstance(module_context, ModuleValue):
|
|
||||||
return
|
|
||||||
for_mod_context = for_mod_value.as_context()
|
|
||||||
for name, trailer in _get_possible_nodes(for_mod_context, string_name):
|
for name, trailer in _get_possible_nodes(for_mod_context, string_name):
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
@@ -142,10 +139,9 @@ def _search_function_executions(inference_state, module_context, funcdef, string
|
|||||||
if i * inference_state.dynamic_params_depth > MAX_PARAM_SEARCHES:
|
if i * inference_state.dynamic_params_depth > MAX_PARAM_SEARCHES:
|
||||||
return
|
return
|
||||||
|
|
||||||
raise NotImplementedError
|
random_context = inference_state.create_context(for_mod_context, name)
|
||||||
random_value = inference_state.create_context(for_mod_context, name)
|
|
||||||
for function_execution in _check_name_for_execution(
|
for function_execution in _check_name_for_execution(
|
||||||
inference_state, random_value, compare_node, name, trailer):
|
inference_state, random_context, compare_node, name, trailer):
|
||||||
found_executions = True
|
found_executions = True
|
||||||
yield function_execution
|
yield function_execution
|
||||||
|
|
||||||
@@ -180,14 +176,14 @@ def _get_possible_nodes(module_value, func_string_name):
|
|||||||
yield name, trailer
|
yield name, trailer
|
||||||
|
|
||||||
|
|
||||||
def _check_name_for_execution(inference_state, value, compare_node, name, trailer):
|
def _check_name_for_execution(inference_state, context, compare_node, name, trailer):
|
||||||
from jedi.inference.value.function import FunctionExecutionContext
|
from jedi.inference.value.function import FunctionExecutionContext
|
||||||
|
|
||||||
def create_func_excs():
|
def create_func_excs():
|
||||||
arglist = trailer.children[1]
|
arglist = trailer.children[1]
|
||||||
if arglist == ')':
|
if arglist == ')':
|
||||||
arglist = None
|
arglist = None
|
||||||
args = TreeArguments(inference_state, value, arglist, trailer)
|
args = TreeArguments(inference_state, context, arglist, trailer)
|
||||||
if value_node.type == 'classdef':
|
if value_node.type == 'classdef':
|
||||||
created_instance = instance.TreeInstance(
|
created_instance = instance.TreeInstance(
|
||||||
inference_state,
|
inference_state,
|
||||||
@@ -200,7 +196,7 @@ def _check_name_for_execution(inference_state, value, compare_node, name, traile
|
|||||||
else:
|
else:
|
||||||
yield v.get_function_execution(args)
|
yield v.get_function_execution(args)
|
||||||
|
|
||||||
for v in inference_state.goto_definitions(value, name):
|
for v in inference_state.goto_definitions(context, name):
|
||||||
value_node = v.tree_node
|
value_node = v.tree_node
|
||||||
if compare_node == value_node:
|
if compare_node == value_node:
|
||||||
for func_execution in create_func_excs():
|
for func_execution in create_func_excs():
|
||||||
@@ -217,11 +213,10 @@ def _check_name_for_execution(inference_state, value, compare_node, name, traile
|
|||||||
nodes = [v.tree_node for v in values]
|
nodes = [v.tree_node for v in values]
|
||||||
if nodes == [compare_node]:
|
if nodes == [compare_node]:
|
||||||
# Found a decorator.
|
# Found a decorator.
|
||||||
module_value = value.get_root_context()
|
module_context = context.get_root_context()
|
||||||
execution_context = next(create_func_excs())
|
execution_context = next(create_func_excs())
|
||||||
for name, trailer in _get_possible_nodes(module_context, params[0].string_name):
|
for name, trailer in _get_possible_nodes(module_context, params[0].string_name):
|
||||||
if value_node.start_pos < name.start_pos < value_node.end_pos:
|
if value_node.start_pos < name.start_pos < value_node.end_pos:
|
||||||
raise NotImplementedError
|
|
||||||
random_value = inference_state.create_context(execution_context, name)
|
random_value = inference_state.create_context(execution_context, name)
|
||||||
iterator = _check_name_for_execution(
|
iterator = _check_name_for_execution(
|
||||||
inference_state,
|
inference_state,
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ def _load_module_from_path(inference_state, file_io, base_names):
|
|||||||
return module
|
return module
|
||||||
|
|
||||||
|
|
||||||
def get_modules_containing_name(inference_state, modules, name):
|
def get_module_contexts_containing_name(inference_state, module_contexts, name):
|
||||||
"""
|
"""
|
||||||
Search a name in the directories of modules.
|
Search a name in the directories of modules.
|
||||||
"""
|
"""
|
||||||
@@ -541,17 +541,17 @@ def get_modules_containing_name(inference_state, modules, name):
|
|||||||
# skip non python modules
|
# skip non python modules
|
||||||
used_mod_paths = set()
|
used_mod_paths = set()
|
||||||
folders_with_names_to_be_checked = []
|
folders_with_names_to_be_checked = []
|
||||||
for m in modules:
|
for module_context in module_contexts:
|
||||||
file_io = m.get_value().file_io
|
path = module_context.py__file__()
|
||||||
if file_io is not None:
|
if path not in used_mod_paths:
|
||||||
path = file_io.path
|
file_io = module_context.get_value().file_io
|
||||||
if path not in used_mod_paths:
|
if file_io is not None:
|
||||||
used_mod_paths.add(path)
|
used_mod_paths.add(path)
|
||||||
folders_with_names_to_be_checked.append((
|
folders_with_names_to_be_checked.append((
|
||||||
file_io.get_parent_folder(),
|
file_io.get_parent_folder(),
|
||||||
m.py__package__()
|
module_context.py__package__()
|
||||||
))
|
))
|
||||||
yield m
|
yield module_context
|
||||||
|
|
||||||
if not settings.dynamic_params_for_other_modules:
|
if not settings.dynamic_params_for_other_modules:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -292,6 +292,7 @@ class DictComprehension(ComprehensionMixin, Sequence):
|
|||||||
def py__simple_getitem__(self, index):
|
def py__simple_getitem__(self, index):
|
||||||
for keys, values in self._iterate():
|
for keys, values in self._iterate():
|
||||||
for k in keys:
|
for k in keys:
|
||||||
|
# TODO remove this isinstance.
|
||||||
if isinstance(k, compiled.CompiledObject):
|
if isinstance(k, compiled.CompiledObject):
|
||||||
# Be careful in the future if refactoring, index could be a
|
# Be careful in the future if refactoring, index could be a
|
||||||
# slice.
|
# slice.
|
||||||
@@ -670,7 +671,7 @@ def _check_array_additions(context, sequence):
|
|||||||
|
|
||||||
debug.dbg('Dynamic array search for %s' % sequence, color='MAGENTA')
|
debug.dbg('Dynamic array search for %s' % sequence, color='MAGENTA')
|
||||||
module_context = context.get_root_context()
|
module_context = context.get_root_context()
|
||||||
if not settings.dynamic_array_additions or isinstance(module_context, compiled.CompiledObject):
|
if not settings.dynamic_array_additions or module_context.is_compiled():
|
||||||
debug.dbg('Dynamic array search aborted.', color='MAGENTA')
|
debug.dbg('Dynamic array search aborted.', color='MAGENTA')
|
||||||
return NO_VALUES
|
return NO_VALUES
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user