From b489019f5bd5750051122b94cc767df47751ecb7 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 5 Mar 2015 01:55:25 +0100 Subject: [PATCH] Most integration tests (except 2) pass if we don't always make the use of an ExprStmt. --- jedi/evaluate/__init__.py | 8 +++++++ jedi/evaluate/docstrings.py | 2 +- jedi/parser/pgen2/parse.py | 2 +- jedi/parser/tree.py | 43 ++++++++++++++++--------------------- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index bfa26493..7b6654c5 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -205,6 +205,10 @@ class Evaluator(object): scope = stmt.get_parent_until(pr.IsScope, include_current=True) if isinstance(stmt, pr.CompFor): stmt = stmt.get_parent_until((pr.ClassOrFunc, pr.ExprStmt)) + if stmt.type != 'expr_stmt': + # We only need to adjust the start_pos for statements, because + # there the name cannot be used. + stmt = atom return self.find_types(scope, atom, stmt.start_pos, search_global=True) elif isinstance(atom, pr.Literal): return [compiled.create(self, atom.eval())] @@ -347,5 +351,9 @@ class Evaluator(object): self.find_types(typ, name, is_goto=True) for typ in types )) else: + if stmt.type != 'expr_stmt': + # We only need to adjust the start_pos for statements, because + # there the name cannot be used. + stmt = name return self.find_types(scope, name, stmt.start_pos, search_global=True, is_goto=True) diff --git a/jedi/evaluate/docstrings.py b/jedi/evaluate/docstrings.py index 661a1706..84137de5 100644 --- a/jedi/evaluate/docstrings.py +++ b/jedi/evaluate/docstrings.py @@ -153,7 +153,7 @@ def _execute_types_in_stmt(evaluator, stmt): doesn't include tuple, list and dict literals, because the stuff they contain is executed. (Used as type information). """ - definitions = evaluator.eval_statement(stmt) + definitions = evaluator.eval_element(stmt) return chain.from_iterable(_execute_array_values(evaluator, d) for d in definitions) diff --git a/jedi/parser/pgen2/parse.py b/jedi/parser/pgen2/parse.py index 18495695..7d6dac73 100644 --- a/jedi/parser/pgen2/parse.py +++ b/jedi/parser/pgen2/parse.py @@ -190,7 +190,7 @@ class PgenParser(object): # If there's exactly one child, return that child instead of creating a # new node. We still create expr_stmt and file_input though, because a # lot of Jedi depends on its logic. - if len(children) != 1 or type in (self.grammar.symbol2number['expr_stmt'], + if len(children) != 1 or type in (-1, self.grammar.symbol2number['file_input']): newnode = self.convert_node(self.grammar, type, children) else: diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index 7654c2ac..3a300d70 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -64,39 +64,34 @@ class DocstringMixin(object): def raw_doc(self): """ Returns a cleaned version of the docstring token. """ if isinstance(self, Module): - stmt = self.children[0] + node = self.children[0] elif isinstance(self, ClassOrFunc): - stmt = self.children[self.children.index(':') + 1] - if is_node(stmt, 'suite'): # Normally a suite - stmt = stmt.children[2] # -> NEWLINE INDENT stmt + node = self.children[self.children.index(':') + 1] + if is_node(node, 'suite'): # Normally a suite + node = node.children[2] # -> NEWLINE INDENT stmt else: # ExprStmt simple_stmt = self.parent c = simple_stmt.parent.children index = c.index(simple_stmt) if not index: return '' - stmt = c[index - 1] + node = c[index - 1] - if is_node(stmt, 'simple_stmt'): - stmt = stmt.children[0] + if is_node(node, 'simple_stmt'): + node = node.children[0] - try: - first = stmt.children[0] - except AttributeError: - pass # Probably a pass Keyword (Leaf). - else: - if first.type == 'string': - # TODO We have to check next leaves until there are no new - # leaves anymore that might be part of the docstring. A - # docstring can also look like this: ``'foo' 'bar' - # Returns a literal cleaned version of the ``Token``. - cleaned = cleandoc(literal_eval(first.value)) - # Since we want the docstr output to be always unicode, just - # force it. - if is_py3 or isinstance(cleaned, unicode): - return cleaned - else: - return unicode(cleaned, 'UTF-8', 'replace') + if node.type == 'string': + # TODO We have to check next leaves until there are no new + # leaves anymore that might be part of the docstring. A + # docstring can also look like this: ``'foo' 'bar' + # Returns a literal cleaned version of the ``Token``. + cleaned = cleandoc(literal_eval(node.value)) + # Since we want the docstr output to be always unicode, just + # force it. + if is_py3 or isinstance(cleaned, unicode): + return cleaned + else: + return unicode(cleaned, 'UTF-8', 'replace') return ''