1
0
forked from VimPlug/jedi

Most integration tests (except 2) pass if we don't always make the use of an ExprStmt.

This commit is contained in:
Dave Halter
2015-03-05 01:55:25 +01:00
parent 5d54922c4b
commit b489019f5b
4 changed files with 29 additions and 26 deletions
+8
View File
@@ -205,6 +205,10 @@ class Evaluator(object):
scope = stmt.get_parent_until(pr.IsScope, include_current=True) scope = stmt.get_parent_until(pr.IsScope, include_current=True)
if isinstance(stmt, pr.CompFor): if isinstance(stmt, pr.CompFor):
stmt = stmt.get_parent_until((pr.ClassOrFunc, pr.ExprStmt)) 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) return self.find_types(scope, atom, stmt.start_pos, search_global=True)
elif isinstance(atom, pr.Literal): elif isinstance(atom, pr.Literal):
return [compiled.create(self, atom.eval())] 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 self.find_types(typ, name, is_goto=True) for typ in types
)) ))
else: 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, return self.find_types(scope, name, stmt.start_pos,
search_global=True, is_goto=True) search_global=True, is_goto=True)
+1 -1
View File
@@ -153,7 +153,7 @@ def _execute_types_in_stmt(evaluator, stmt):
doesn't include tuple, list and dict literals, because the stuff they doesn't include tuple, list and dict literals, because the stuff they
contain is executed. (Used as type information). 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) return chain.from_iterable(_execute_array_values(evaluator, d) for d in definitions)
+1 -1
View File
@@ -190,7 +190,7 @@ class PgenParser(object):
# If there's exactly one child, return that child instead of creating a # 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 # new node. We still create expr_stmt and file_input though, because a
# lot of Jedi depends on its logic. # 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']): self.grammar.symbol2number['file_input']):
newnode = self.convert_node(self.grammar, type, children) newnode = self.convert_node(self.grammar, type, children)
else: else:
+19 -24
View File
@@ -64,39 +64,34 @@ class DocstringMixin(object):
def raw_doc(self): def raw_doc(self):
""" Returns a cleaned version of the docstring token. """ """ Returns a cleaned version of the docstring token. """
if isinstance(self, Module): if isinstance(self, Module):
stmt = self.children[0] node = self.children[0]
elif isinstance(self, ClassOrFunc): elif isinstance(self, ClassOrFunc):
stmt = self.children[self.children.index(':') + 1] node = self.children[self.children.index(':') + 1]
if is_node(stmt, 'suite'): # Normally a suite if is_node(node, 'suite'): # Normally a suite
stmt = stmt.children[2] # -> NEWLINE INDENT stmt node = node.children[2] # -> NEWLINE INDENT stmt
else: # ExprStmt else: # ExprStmt
simple_stmt = self.parent simple_stmt = self.parent
c = simple_stmt.parent.children c = simple_stmt.parent.children
index = c.index(simple_stmt) index = c.index(simple_stmt)
if not index: if not index:
return '' return ''
stmt = c[index - 1] node = c[index - 1]
if is_node(stmt, 'simple_stmt'): if is_node(node, 'simple_stmt'):
stmt = stmt.children[0] node = node.children[0]
try: if node.type == 'string':
first = stmt.children[0] # TODO We have to check next leaves until there are no new
except AttributeError: # leaves anymore that might be part of the docstring. A
pass # Probably a pass Keyword (Leaf). # docstring can also look like this: ``'foo' 'bar'
else: # Returns a literal cleaned version of the ``Token``.
if first.type == 'string': cleaned = cleandoc(literal_eval(node.value))
# TODO We have to check next leaves until there are no new # Since we want the docstr output to be always unicode, just
# leaves anymore that might be part of the docstring. A # force it.
# docstring can also look like this: ``'foo' 'bar' if is_py3 or isinstance(cleaned, unicode):
# Returns a literal cleaned version of the ``Token``. return cleaned
cleaned = cleandoc(literal_eval(first.value)) else:
# Since we want the docstr output to be always unicode, just return unicode(cleaned, 'UTF-8', 'replace')
# force it.
if is_py3 or isinstance(cleaned, unicode):
return cleaned
else:
return unicode(cleaned, 'UTF-8', 'replace')
return '' return ''