Use create_name instead of duplicated logic

This commit is contained in:
Dave Halter
2019-09-05 00:04:24 +02:00
parent 02046d5333
commit 4d332c32c0

View File

@@ -34,7 +34,6 @@ from jedi.inference import usages
from jedi.inference.arguments import try_iter_content
from jedi.inference.helpers import get_module_names, infer_call_of_leaf
from jedi.inference.sys_path import transform_path_to_dotted
from jedi.inference.names import TreeNameDefinition, AnonymousParamName
from jedi.inference.syntax_tree import tree_name_to_values
from jedi.inference.value import ModuleValue
from jedi.inference.base_value import ValueSet
@@ -503,22 +502,13 @@ def names(source=None, path=None, encoding='utf-8', all_scopes=False,
is_def = _def._name.tree_name.is_definition()
return definitions and is_def or references and not is_def
def create_name(name):
context = module_context.create_context(name)
if name.parent.type == 'param':
func = tree.search_ancestor(name, 'funcdef', 'lambdef')
func = context.get_root_context().create_value(func)
return AnonymousParamName(func, name)
else:
return TreeNameDefinition(context, name)
# Set line/column to a random position, because they don't matter.
script = Script(source, line=1, column=0, path=path, encoding=encoding, environment=environment)
module_context = script._get_module_context()
defs = [
classes.Definition(
script._inference_state,
create_name(name)
module_context.create_name(name)
) for name in get_module_names(script._module_node, all_scopes)
]
return sorted(filter(def_ref_filter, defs), key=lambda x: (x.line, x.column))