From cffb3d24833ed49bd6ff4f6fc0fd3f444f68edb8 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Tue, 6 Nov 2012 22:02:59 +0100 Subject: [PATCH 1/2] Refactoring: add Function.doc --- jedi/api.py | 9 ++------- jedi/parsing.py | 5 +++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index ab2af7d0..f0996fc5 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -74,14 +74,9 @@ class Completion(object): def doc(self): """ Return a document string for this completion object. """ try: - parent = self.name.parent() - try: - return '%s\n\n%s' % (parent.get_call_signature(), - parent.docstr) - except AttributeError: - return str(parent.docstr) + return self.name.parent().doc except AttributeError: - return '' + return self.raw_doc @property def raw_doc(self): diff --git a/jedi/parsing.py b/jedi/parsing.py index dfb6212e..ad7dfe1b 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -410,6 +410,11 @@ class Function(Scope): lines[-1] += ')' return '\n'.join(lines) + @property + def doc(self): + """ Return a document string including call signature. """ + return '%s\n\n%s' % (self.get_call_signature(), self.docstr) + class Flow(Scope): """ From cfd4bb6fc66e60c977f3a6f8cd93b1d929264fa1 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Tue, 6 Nov 2012 22:09:45 +0100 Subject: [PATCH 2/2] Use Function.doc from api.Definition.doc --- jedi/api.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jedi/api.py b/jedi/api.py index f0996fc5..2d3fbb3b 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -135,6 +135,14 @@ class Definition(dynamic.BaseOutput): @property def doc(self): """ Returns the docstr, behaves like `Completion.doc`. """ + try: + return self.definition.doc + except AttributeError: + return self.raw_doc + + @property + def raw_doc(self): + """ Returns the docstring `__doc__` for any object """ try: return str(self.definition.docstr) except AttributeError: