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
|
||||
# contain it).
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -152,8 +152,10 @@ class Parser(object):
|
||||
arr = self.scope_names_stack[-1].setdefault(name.value, [])
|
||||
arr.append(name)
|
||||
return name
|
||||
elif type in (tokenize.STRING, tokenize.NUMBER):
|
||||
return pr.Literal(value, start_pos, prefix)
|
||||
elif type == tokenize.STRING:
|
||||
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):
|
||||
return pr.Whitespace(value, start_pos, prefix)
|
||||
else:
|
||||
|
||||
@@ -95,24 +95,36 @@ class GetCodeState(object):
|
||||
class DocstringMixin(object):
|
||||
__slots__ = ()
|
||||
|
||||
def add_docstr(self, token):
|
||||
""" Clean up a docstring """
|
||||
self._doc_token = token
|
||||
|
||||
@property
|
||||
def raw_doc(self):
|
||||
""" 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:
|
||||
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``.
|
||||
cleaned = cleandoc(literal_eval(self._doc_token.string))
|
||||
# Since we want the docstr output to be always unicode, just force
|
||||
# it.
|
||||
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')
|
||||
except AttributeError:
|
||||
return u('')
|
||||
return ''
|
||||
|
||||
|
||||
class Base(object):
|
||||
@@ -330,6 +342,14 @@ class Literal(Leaf):
|
||||
return "<%s: %s>" % (type(self).__name__, self.value)
|
||||
|
||||
|
||||
class Number(Literal):
|
||||
pass
|
||||
|
||||
|
||||
class String(Literal):
|
||||
pass
|
||||
|
||||
|
||||
class Operator(Leaf):
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
Reference in New Issue
Block a user