diff --git a/jedi/inference/__init__.py b/jedi/inference/__init__.py index 42d5c56a..7606be42 100644 --- a/jedi/inference/__init__.py +++ b/jedi/inference/__init__.py @@ -104,6 +104,7 @@ class InferenceState(object): self.project = project self.access_cache = {} self.allow_descriptor_getattr = False + self.flow_analysis_enabled = True self.reset_recursion_limitations() diff --git a/jedi/inference/flow_analysis.py b/jedi/inference/flow_analysis.py index 0e0fadf0..184f367f 100644 --- a/jedi/inference/flow_analysis.py +++ b/jedi/inference/flow_analysis.py @@ -43,7 +43,8 @@ def _get_flow_scopes(node): def reachability_check(context, value_scope, node, origin_scope=None): - if is_big_annoying_library(context): + if is_big_annoying_library(context) \ + or not context.inference_state.flow_analysis_enabled: return UNSURE first_flow_scope = get_parent_scope(node, include_flows=True) diff --git a/jedi/inference/references.py b/jedi/inference/references.py index 9f10882d..20b287f3 100644 --- a/jedi/inference/references.py +++ b/jedi/inference/references.py @@ -92,15 +92,23 @@ def _find_global_variables(names, search_name): def find_references(module_context, tree_name): + inf = module_context.inference_state search_name = tree_name.value - found_names = _find_defining_names(module_context, tree_name) + + # We disable flow analysis, because if we have ifs that are only true in + # certain cases, we want both sides. + try: + inf.flow_analysis_enabled = False + found_names = _find_defining_names(module_context, tree_name) + finally: + inf.flow_analysis_enabled = True + found_names_dct = _dictionarize(found_names) module_contexts = set(d.get_root_context() for d in found_names) module_contexts = set(m for m in module_contexts if not m.is_compiled()) non_matching_reference_maps = {} - inf = module_context.inference_state potential_modules = imports.get_module_contexts_containing_name( inf, module_contexts, search_name ) diff --git a/test/completion/stub_folder/with_stub_folder/nested_stub_only.pyi b/test/completion/stub_folder/with_stub_folder/nested_stub_only.pyi index 4f2f4239..6b19f90b 100644 --- a/test/completion/stub_folder/with_stub_folder/nested_stub_only.pyi +++ b/test/completion/stub_folder/with_stub_folder/nested_stub_only.pyi @@ -1 +1,4 @@ -in_stub_only: int +if 1: + in_stub_only: int +else: + in_stub_only: int diff --git a/test/completion/usages.py b/test/completion/usages.py index 8fb63082..6de4afb8 100644 --- a/test/completion/usages.py +++ b/test/completion/usages.py @@ -358,5 +358,5 @@ 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 from stub_folder.with_stub_folder.nested_stub_only import in_stub_only -#< ('stub:stub_folder.with_stub_folder.nested_stub_only', 1, 0), ('stubs', 64, 17), (-2, 58), (0, 0) +#< ('stub:stub_folder.with_stub_folder.nested_stub_only', 2, 4), ('stub:stub_folder.with_stub_folder.nested_stub_only', 4, 4), ('stubs', 64, 17), (-2, 58), (0, 0) in_stub_only