From e1564da23d7f5cd5169b9dc90a2fc58182de1f07 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 13 Jan 2020 20:45:53 +0100 Subject: [PATCH] Make sure to find both stubs and non-stubs with usages --- jedi/inference/references.py | 9 +++++++++ test/completion/usages.py | 8 ++++++++ test/run.py | 5 ++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/jedi/inference/references.py b/jedi/inference/references.py index ce61cbf6..9f10882d 100644 --- a/jedi/inference/references.py +++ b/jedi/inference/references.py @@ -1,5 +1,6 @@ from jedi.inference import imports from jedi.inference.filters import ParserTreeFilter +from jedi.inference.gradual.conversion import convert_names def _resolve_names(definition_names, avoid_names=()): @@ -29,6 +30,14 @@ def _dictionarize(names): def _find_defining_names(module_context, tree_name): found_names = _find_names(module_context, tree_name) + for name in list(found_names): + # Convert from/to stubs, because those might also be usages. + found_names |= set(convert_names( + [name], + only_stubs=not name.get_root_context().is_stub(), + prefer_stub_to_compiled=False + )) + found_names |= set(_find_global_variables(found_names, tree_name.value)) for name in list(found_names): if name.api_type == 'param' or name.tree_name is None \ diff --git a/test/completion/usages.py b/test/completion/usages.py index 700e0ede..12cff83d 100644 --- a/test/completion/usages.py +++ b/test/completion/usages.py @@ -349,3 +349,11 @@ class DefinitelyNotGlobal: def my_global(self): def my_global(self): pass + +# ----------------- +# stubs +# ----------------- + +from stub_folder import with_stub +#< ('stub:stub_folder.with_stub', 5, 4), ('stub_folder.with_stub', 5, 4), (0, 10) +with_stub.stub_function diff --git a/test/run.py b/test/run.py index f9418dfa..ff52f5fe 100755 --- a/test/run.py +++ b/test/run.py @@ -265,7 +265,10 @@ class IntegrationTestCase(BaseTestCase): result = self.script(environment).find_references(self.line_nr, self.column) self.correct = self.correct.strip() compare = sorted( - (re.sub(r'^test\.completion\.', '', r.module_name), r.line, r.column) + (('stub:' if r.is_stub() else '') + + re.sub(r'^test\.completion\.', '', r.module_name), + r.line, + r.column) for r in result ) wanted = []