From fa0f4b1e00f355926f3b681c39b7afbcdd24fa24 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 5 Nov 2014 21:29:54 +0100 Subject: [PATCH] Further small flow_analysis corrections. Keywords are only equal to other keywords if they are the same. Not in case of the same value anymore. --- jedi/evaluate/__init__.py | 6 +++--- jedi/evaluate/flow_analysis.py | 11 ++++++++--- jedi/evaluate/param.py | 2 +- jedi/parser/representation.py | 2 ++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index b81c07ca..7579b5db 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -210,9 +210,9 @@ class Evaluator(object): """ if isinstance(atom, pr.Name): # This is the first global lookup. - stmt = atom.get_parent_until((pr.ExprStmt, pr.ReturnStmt, pr.Scope)) - return self.find_types(stmt.get_parent_until(pr.IsScope), atom, stmt.start_pos, - search_global=True) + stmt = atom.get_definition() + return self.find_types(stmt.get_parent_until(pr.IsScope), atom, + stmt.start_pos, search_global=True) elif isinstance(atom, pr.Literal): return [compiled.create(self, atom.eval())] else: diff --git a/jedi/evaluate/flow_analysis.py b/jedi/evaluate/flow_analysis.py index fe9bada9..783a044a 100644 --- a/jedi/evaluate/flow_analysis.py +++ b/jedi/evaluate/flow_analysis.py @@ -34,9 +34,7 @@ UNSURE = Status(None, 'unsure') def break_check(evaluator, base_scope, stmt, origin_scope=None): from jedi.evaluate.representation import wrap - base_scope = wrap(evaluator, base_scope) element_scope = wrap(evaluator, stmt.parent) - # Direct parents get resolved, we filter scopes that are separate branches. # This makes sense for autocompletion and static analysis. For actual # Python it doesn't matter, because we're talking about potentially @@ -46,6 +44,13 @@ def break_check(evaluator, base_scope, stmt, origin_scope=None): if element_scope == s: return REACHABLE s = s.parent + return _break_check(evaluator, stmt, base_scope, element_scope) + + +def _break_check(evaluator, stmt, base_scope, element_scope): + from jedi.evaluate.representation import wrap + element_scope = wrap(evaluator, element_scope) + base_scope = wrap(evaluator, base_scope) reachable = REACHABLE if isinstance(element_scope, pr.IfStmt): @@ -66,7 +71,7 @@ def break_check(evaluator, base_scope, stmt, origin_scope=None): return reachable if base_scope != element_scope and base_scope != element_scope.parent: - return reachable & break_check(evaluator, base_scope, element_scope.parent) + return reachable & _break_check(evaluator, stmt, base_scope, element_scope.parent) return reachable diff --git a/jedi/evaluate/param.py b/jedi/evaluate/param.py index 933a22b8..52202bdc 100644 --- a/jedi/evaluate/param.py +++ b/jedi/evaluate/param.py @@ -153,7 +153,7 @@ class ExecutedParam(pr.Param): def eval(self, evaluator): types = [] for v in self.values: - if isinstance(v, (pr.Simple, pr.Name, pr.Literal)): + if isinstance(v, (pr.Simple, pr.Leaf)): types += evaluator.eval_element(v) else: types.append(v) diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 85f713d9..5bb6bbcd 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -334,6 +334,8 @@ class Keyword(Leaf): Make comparisons with strings easy. Improves the readability of the parser. """ + if isinstance(other, Keyword): + return self is other return self.value == other def __ne__(self, other):