mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Make separate methods for goto_import and infer_import
This commit is contained in:
@@ -308,7 +308,7 @@ class InferenceState(object):
|
|||||||
elif type_ == 'param':
|
elif type_ == 'param':
|
||||||
return [ParamName(context, name)]
|
return [ParamName(context, name)]
|
||||||
elif type_ in ('import_from', 'import_name'):
|
elif type_ in ('import_from', 'import_name'):
|
||||||
module_names = imports.infer_import(context, name, is_goto=True)
|
module_names = imports.goto_import(context, name)
|
||||||
return module_names
|
return module_names
|
||||||
else:
|
else:
|
||||||
return [TreeNameDefinition(context, name)]
|
return [TreeNameDefinition(context, name)]
|
||||||
|
|||||||
@@ -57,7 +57,16 @@ class ModuleCache(object):
|
|||||||
# This memoization is needed, because otherwise we will infinitely loop on
|
# This memoization is needed, because otherwise we will infinitely loop on
|
||||||
# certain imports.
|
# certain imports.
|
||||||
@inference_state_method_cache(default=NO_VALUES)
|
@inference_state_method_cache(default=NO_VALUES)
|
||||||
def infer_import(context, tree_name, is_goto=False):
|
def infer_import(context, tree_name):
|
||||||
|
return _infer_import(context, tree_name, is_goto=False)
|
||||||
|
|
||||||
|
|
||||||
|
@inference_state_method_cache(default=[])
|
||||||
|
def goto_import(context, tree_name):
|
||||||
|
return _infer_import(context, tree_name, is_goto=True)
|
||||||
|
|
||||||
|
|
||||||
|
def _infer_import(context, tree_name, is_goto=False):
|
||||||
module_context = context.get_root_context()
|
module_context = context.get_root_context()
|
||||||
import_node = search_ancestor(tree_name, 'import_name', 'import_from')
|
import_node = search_ancestor(tree_name, 'import_name', 'import_from')
|
||||||
import_path = import_node.get_path_for_name(tree_name)
|
import_path = import_node.get_path_for_name(tree_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user