From bd24ee2ab3dc8bff6dcf4da67f0af8d8e3c65547 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 24 Aug 2019 00:45:21 +0200 Subject: [PATCH] Move a paragraph --- jedi/inference/finder.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/jedi/inference/finder.py b/jedi/inference/finder.py index d46047ea..1082216a 100644 --- a/jedi/inference/finder.py +++ b/jedi/inference/finder.py @@ -43,7 +43,6 @@ class NameFinder(object): else: self._string_name = name_or_str self._position = position - self._found_predefined_types = None self._analysis_errors = analysis_errors def find(self, names, attribute_lookup): @@ -51,7 +50,24 @@ class NameFinder(object): :params bool attribute_lookup: Tell to logic if we're accessing the attribute or the contents of e.g. a function. """ - if self._found_predefined_types is not None and names: + found_predefined_types = None + # This paragraph is currently needed for proper branch type inference + # (static analysis). + if self._context.predefined_names and isinstance(self._name, tree.Name): + node = self._name + while node is not None and not is_scope(node): + node = node.parent + if node.type in ("if_stmt", "for_stmt", "comp_for", 'sync_comp_for'): + try: + name_dict = self._context.predefined_names[node] + types = name_dict[self._string_name] + except KeyError: + continue + else: + found_predefined_types = types + break + + if found_predefined_types is not None and names: check = flow_analysis.reachability_check( context=self._context, value_scope=self._context.tree_node, @@ -59,7 +75,7 @@ class NameFinder(object): ) if check is flow_analysis.UNREACHABLE: return NO_VALUES - return self._found_predefined_types + return found_predefined_types types = self._names_to_types(names) self.check_issues(names, types, attribute_lookup) @@ -84,22 +100,6 @@ class NameFinder(object): ``filters``), until a name fits. """ names = [] - # This paragraph is currently needed for proper branch type inference - # (static analysis). - if self._context.predefined_names and isinstance(self._name, tree.Name): - node = self._name - while node is not None and not is_scope(node): - node = node.parent - if node.type in ("if_stmt", "for_stmt", "comp_for", 'sync_comp_for'): - try: - name_dict = self._context.predefined_names[node] - types = name_dict[self._string_name] - except KeyError: - continue - else: - self._found_predefined_types = types - break - for filter in filters: names = filter.get(self._string_name) if names: