diff --git a/jedi/evaluate/compiled/fake.py b/jedi/evaluate/compiled/fake.py index d9d22856..436fd6f4 100644 --- a/jedi/evaluate/compiled/fake.py +++ b/jedi/evaluate/compiled/fake.py @@ -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 diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 35a7fed1..f016bfc9 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -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: diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 0b4d9b64..7eafe05d 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -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: - # 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. - if is_py3 or isinstance(cleaned, unicode): - return cleaned - else: - return unicode(cleaned, 'UTF-8', 'replace') + first = stmt.children[0] except AttributeError: - return u('') + 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(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') + 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