forked from VimPlug/jedi
At least functions generate docstrings again.
This commit is contained in:
@@ -104,7 +104,8 @@ def get_faked(module, obj, name=None):
|
|||||||
# Set the docstr which was previously not set (faked modules don't
|
# Set the docstr which was previously not set (faked modules don't
|
||||||
# contain it).
|
# contain it).
|
||||||
doc = '''"""%s"""''' % obj.__doc__ # TODO need escapes.
|
doc = '''"""%s"""''' % obj.__doc__ # TODO need escapes.
|
||||||
result.add_docstr(tokenize.Token(tokenize.STRING, doc, (0, 0)))
|
# TODO We need to add the docstr in a proper way.
|
||||||
|
#result.add_docstr(tokenize.Token(tokenize.STRING, doc, (0, 0)))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -152,8 +152,10 @@ class Parser(object):
|
|||||||
arr = self.scope_names_stack[-1].setdefault(name.value, [])
|
arr = self.scope_names_stack[-1].setdefault(name.value, [])
|
||||||
arr.append(name)
|
arr.append(name)
|
||||||
return name
|
return name
|
||||||
elif type in (tokenize.STRING, tokenize.NUMBER):
|
elif type == tokenize.STRING:
|
||||||
return pr.Literal(value, start_pos, prefix)
|
return pr.String(value, start_pos, prefix)
|
||||||
|
elif type == tokenize.NUMBER:
|
||||||
|
return pr.Number(value, start_pos, prefix)
|
||||||
elif type in (tokenize.NEWLINE, tokenize.ENDMARKER):
|
elif type in (tokenize.NEWLINE, tokenize.ENDMARKER):
|
||||||
return pr.Whitespace(value, start_pos, prefix)
|
return pr.Whitespace(value, start_pos, prefix)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -95,24 +95,36 @@ class GetCodeState(object):
|
|||||||
class DocstringMixin(object):
|
class DocstringMixin(object):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def add_docstr(self, token):
|
|
||||||
""" Clean up a docstring """
|
|
||||||
self._doc_token = token
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
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, SubModule):
|
||||||
|
stmt = self.children[0]
|
||||||
|
else:
|
||||||
|
stmt = self.children[-1]
|
||||||
|
if is_node(stmt, 'suite'): # Normally a suite
|
||||||
|
stmt = stmt.children[2] # -> NEWLINE INDENT stmt
|
||||||
|
if is_node(stmt, 'simple_stmt'):
|
||||||
|
stmt = stmt.children[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
first = stmt.children[0]
|
||||||
|
except AttributeError:
|
||||||
|
pass # Probably a pass Keyword (Leaf).
|
||||||
|
else:
|
||||||
|
if isinstance(first, 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``.
|
# Returns a literal cleaned version of the ``Token``.
|
||||||
cleaned = cleandoc(literal_eval(self._doc_token.string))
|
cleaned = cleandoc(literal_eval(first.value))
|
||||||
# Since we want the docstr output to be always unicode, just force
|
# Since we want the docstr output to be always unicode, just
|
||||||
# it.
|
# force it.
|
||||||
if is_py3 or isinstance(cleaned, unicode):
|
if is_py3 or isinstance(cleaned, unicode):
|
||||||
return cleaned
|
return cleaned
|
||||||
else:
|
else:
|
||||||
return unicode(cleaned, 'UTF-8', 'replace')
|
return unicode(cleaned, 'UTF-8', 'replace')
|
||||||
except AttributeError:
|
return ''
|
||||||
return u('')
|
|
||||||
|
|
||||||
|
|
||||||
class Base(object):
|
class Base(object):
|
||||||
@@ -330,6 +342,14 @@ class Literal(Leaf):
|
|||||||
return "<%s: %s>" % (type(self).__name__, self.value)
|
return "<%s: %s>" % (type(self).__name__, self.value)
|
||||||
|
|
||||||
|
|
||||||
|
class Number(Literal):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class String(Literal):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Operator(Leaf):
|
class Operator(Leaf):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|||||||
Reference in New Issue
Block a user