mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Refactor some dynamic function arguments things
This commit is contained in:
@@ -16,7 +16,6 @@ It works as follows:
|
|||||||
- search for function calls named ``foo``
|
- search for function calls named ``foo``
|
||||||
- execute these calls and check the input.
|
- execute these calls and check the input.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.parser_utils import get_parent_scope
|
from jedi.parser_utils import get_parent_scope
|
||||||
@@ -113,23 +112,29 @@ def _search_function_arguments(module_context, funcdef, string_name):
|
|||||||
string_name = cls.name.value
|
string_name = cls.name.value
|
||||||
compare_node = cls
|
compare_node = cls
|
||||||
|
|
||||||
|
module_contexts = imports.get_module_contexts_containing_name(
|
||||||
|
module_context.inference_state, [module_context], string_name
|
||||||
|
)
|
||||||
|
return _search_function_arguments_for_module(
|
||||||
|
module_contexts, funcdef, compare_node, string_name)
|
||||||
|
|
||||||
|
|
||||||
|
def _search_function_arguments_for_module(module_contexts, funcdef, compare_node, string_name):
|
||||||
found_arguments = False
|
found_arguments = False
|
||||||
i = 0
|
i = 0
|
||||||
inference_state = module_context.inference_state
|
for module_context in module_contexts:
|
||||||
for for_mod_context in imports.get_module_contexts_containing_name(
|
for name, trailer in _get_potential_nodes(module_context, string_name):
|
||||||
inference_state, [module_context], string_name):
|
|
||||||
for name, trailer in _get_potential_nodes(for_mod_context, string_name):
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# This is a simple way to stop Jedi's dynamic param recursion
|
# This is a simple way to stop Jedi's dynamic param recursion
|
||||||
# from going wild: The deeper Jedi's in the recursion, the less
|
# from going wild: The deeper Jedi's in the recursion, the less
|
||||||
# code should be inferred.
|
# code should be inferred.
|
||||||
if i * inference_state.dynamic_params_depth > MAX_PARAM_SEARCHES:
|
if i * module_context.inference_state.dynamic_params_depth > MAX_PARAM_SEARCHES:
|
||||||
return
|
return
|
||||||
|
|
||||||
random_context = for_mod_context.create_context(name)
|
random_context = module_context.create_context(name)
|
||||||
for arguments in _check_name_for_execution(
|
for arguments in _check_name_for_execution(
|
||||||
inference_state, random_context, compare_node, name, trailer):
|
module_context.inference_state, random_context, compare_node, name, trailer):
|
||||||
found_arguments = True
|
found_arguments = True
|
||||||
yield arguments
|
yield arguments
|
||||||
|
|
||||||
@@ -201,9 +206,8 @@ def _check_name_for_execution(inference_state, context, compare_node, name, trai
|
|||||||
if len(param_names) != 1:
|
if len(param_names) != 1:
|
||||||
continue
|
continue
|
||||||
values = param_names[0].infer()
|
values = param_names[0].infer()
|
||||||
nodes = [v.tree_node for v in values]
|
if [v.tree_node for v in values] == [compare_node]:
|
||||||
if nodes == [compare_node]:
|
# Found a decorator or something that looks like it.
|
||||||
# Found a decorator.
|
|
||||||
module_context = context.get_root_context()
|
module_context = context.get_root_context()
|
||||||
execution_context = value.as_context(next(create_func_excs(value)))
|
execution_context = value.as_context(next(create_func_excs(value)))
|
||||||
potential_nodes = _get_potential_nodes(module_context, param_names[0].string_name)
|
potential_nodes = _get_potential_nodes(module_context, param_names[0].string_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user