forked from VimPlug/jedi
Get docstrings working.
This commit is contained in:
@@ -166,6 +166,9 @@ class Evaluator(object):
|
||||
|
||||
@memoize_default(evaluator_is_first_arg=True)
|
||||
def eval_element(self, element):
|
||||
if isinstance(element, iterable.AlreadyEvaluated):
|
||||
return element
|
||||
|
||||
debug.dbg('eval_element %s@%s', element, element.start_pos)
|
||||
if isinstance(element, (pr.Name, pr.Literal)) or pr.is_node(element, 'atom'):
|
||||
return self._eval_atom(element)
|
||||
|
||||
@@ -22,8 +22,7 @@ from textwrap import dedent
|
||||
from jedi.evaluate.cache import memoize_default
|
||||
from jedi.parser import Parser
|
||||
from jedi.common import indent_block
|
||||
from jedi.evaluate.iterable import Array
|
||||
from jedi.evaluate import helpers
|
||||
from jedi.evaluate.iterable import Array, FakeSequence, AlreadyEvaluated
|
||||
|
||||
|
||||
DOCSTRING_PARAM_PATTERNS = [
|
||||
@@ -117,7 +116,7 @@ def _strip_rst_role(type_str):
|
||||
def _evaluate_for_statement_string(evaluator, string, module):
|
||||
code = dedent("""
|
||||
def pseudo_docstring_stuff():
|
||||
'''Create a pseudo function for docstring statements.'''
|
||||
# Create a pseudo function for docstring statements.
|
||||
%s
|
||||
""")
|
||||
if string is None:
|
||||
@@ -162,10 +161,8 @@ def _execute_array_values(evaluator, array):
|
||||
values = []
|
||||
for typ in array.values():
|
||||
objects = _execute_array_values(evaluator, typ)
|
||||
values.append(helpers.FakeStatement(objects))
|
||||
arr = helpers.FakeArray(values, array.parent, array.type)
|
||||
# Wrap it, because that's what the evaluator knows.
|
||||
return [Array(evaluator, arr)]
|
||||
values.append([AlreadyEvaluated(objects)])
|
||||
return [FakeSequence(evaluator, values, array.type)]
|
||||
else:
|
||||
return evaluator.execute(array)
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ class Array(IterableWrapper):
|
||||
return iter(self._items())
|
||||
|
||||
def __repr__(self):
|
||||
return "<e%s of %s>" % (type(self).__name__, self._atom)
|
||||
return "<%s of %s>" % (type(self).__name__, self._atom)
|
||||
|
||||
|
||||
class _FakeArray(Array):
|
||||
@@ -325,6 +325,11 @@ class FakeSequence(_FakeArray):
|
||||
for v in self._sequence_values[index]))
|
||||
|
||||
|
||||
class AlreadyEvaluated(frozenset):
|
||||
"""A simple container to add already evaluated objects to an array."""
|
||||
pass
|
||||
|
||||
|
||||
class FakeDict(_FakeArray):
|
||||
def __init__(self, evaluator, dct):
|
||||
super(FakeDict, self).__init__(evaluator, dct, pr.Array.DICT)
|
||||
|
||||
@@ -543,9 +543,7 @@ class Scope(Simple, DocstringMixin):
|
||||
|
||||
@property
|
||||
def statements(self):
|
||||
return [s for c in self.children if is_node(c, 'simple_stmt')
|
||||
for s in c.children if isinstance(s, (ExprStmt, Import,
|
||||
KeywordStatement))]
|
||||
return self._search_in_scope((ExprStmt, Import, KeywordStatement))
|
||||
|
||||
def is_scope(self):
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user