Fix issues where references were identified as definitions

This commit is contained in:
Dave Halter
2020-03-06 14:23:12 +01:00
parent 6e3bd38600
commit c7a862ec19
3 changed files with 24 additions and 8 deletions
+7 -6
View File
@@ -550,17 +550,18 @@ class Script(object):
return parso_to_jedi_errors(self._inference_state.grammar, self._module_node)
def _names(self, all_scopes=False, definitions=True, references=False):
def def_ref_filter(name):
is_def = name.tree_name.is_definition()
return definitions and is_def or references and not is_def
# Set line/column to a random position, because they don't matter.
module_context = self._get_module_context()
defs = [
module_context.create_name(name)
for name in get_module_names(self._module_node, all_scopes)
for name in get_module_names(
self._module_node,
all_scopes=all_scopes,
definitions=definitions,
references=references,
)
]
return sorted(filter(def_ref_filter, defs), key=lambda x: x.start_pos)
return sorted(defs, key=lambda x: x.start_pos)
@no_py2_support
def rename(self, line=None, column=None, **kwargs):
+6 -2
View File
@@ -122,11 +122,15 @@ def get_names_of_node(node):
return list(chain.from_iterable(get_names_of_node(c) for c in children))
def get_module_names(module, all_scopes):
def get_module_names(module, all_scopes, definitions=True, references=False):
"""
Returns a dictionary with name parts as keys and their call paths as
values.
"""
def def_ref_filter(name):
is_def = name.is_definition()
return definitions and is_def or references and not is_def
names = list(chain.from_iterable(module.get_used_names().values()))
if not all_scopes:
# We have to filter all the names that don't have the module as a
@@ -142,7 +146,7 @@ def get_module_names(module, all_scopes):
return parent_scope in (module, None)
names = [n for n in names if is_module_scope_name(n)]
return names
return filter(def_ref_filter, names)
def is_string(value):