From febe65f7377bdb9e1c87167e069015c4808cf55d Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 29 Jan 2018 00:56:29 +0100 Subject: [PATCH] Disable predefined name analysis (if stmts) for all non-analysis tasks It's really buggy and caused quite a few issues --- jedi/evaluate/__init__.py | 6 +++++- jedi/evaluate/filters.py | 5 ++++- jedi/evaluate/finder.py | 8 +++++--- test/completion/stdlib.py | 4 ++++ test/static_analysis/branches.py | 6 ++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index f52f1391..29438d31 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -135,7 +135,11 @@ class Evaluator(object): if_stmt = None break predefined_if_name_dict = context.predefined_names.get(if_stmt) - if predefined_if_name_dict is None and if_stmt and if_stmt.type == 'if_stmt': + # TODO there's a lot of issues with this one. We actually should do + # this in a different way. Caching should only be active in certain + # cases and this all sucks. + if predefined_if_name_dict is None and if_stmt \ + and if_stmt.type == 'if_stmt' and self.is_analysis: if_stmt_test = if_stmt.children[1] name_dicts = [{}] # If we already did a check, we don't want to do it again -> If diff --git a/jedi/evaluate/filters.py b/jedi/evaluate/filters.py index f34b2810..88e4a62c 100644 --- a/jedi/evaluate/filters.py +++ b/jedi/evaluate/filters.py @@ -212,7 +212,10 @@ class ParserTreeFilter(AbstractUsedNamesFilter): def _check_flows(self, names): for name in sorted(names, key=lambda name: name.start_pos, reverse=True): check = flow_analysis.reachability_check( - self._node_context, self._parser_scope, name, self._origin_scope + context=self._node_context, + context_scope=self._parser_scope, + node=name, + origin_scope=self._origin_scope ) if check is not flow_analysis.UNREACHABLE: yield name diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 3243f21b..8e100170 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -56,7 +56,10 @@ class NameFinder(object): names = self.filter_name(filters) if self._found_predefined_types is not None and names: check = flow_analysis.reachability_check( - self._context, self._context.tree_node, self._name) + context=self._context, + context_scope=self._context.tree_node, + node=self._name, + ) if check is flow_analysis.UNREACHABLE: return ContextSet() return self._found_predefined_types @@ -102,8 +105,7 @@ class NameFinder(object): ``filters``), until a name fits. """ names = [] - if self._context.predefined_names: - # TODO is this ok? node might not always be a tree.Name + 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 diff --git a/test/completion/stdlib.py b/test/completion/stdlib.py index b6b739af..30d7ce07 100644 --- a/test/completion/stdlib.py +++ b/test/completion/stdlib.py @@ -65,6 +65,10 @@ class X(): pass #? type type(X) +if os.path.isfile(): + #? ['abspath'] + fails = os.path.abspath + with open('foo') as f: for line in f.readlines(): diff --git a/test/static_analysis/branches.py b/test/static_analysis/branches.py index 6828d33c..458d854b 100644 --- a/test/static_analysis/branches.py +++ b/test/static_analysis/branches.py @@ -31,6 +31,12 @@ else: #! 6 type-error-operation z = x + y + +# TODO enable this one. +#x = 3 +#if x != 1: +# x.upper() + # ----------------- # With a function # -----------------