Jedi: docstring is empty for completions

Created on 10 Feb 2017  路  4Comments  路  Source: davidhalter/jedi

Version 0.10.0

>>> import jedi
>>> source = '''
... import time
... time.slee'''
>>> script = jedi.Script(source, 3, len('time.slee'), 'example.py')
>>> comp = script.completions()
>>> len(comp)
1
>>> comp[0].docstring()
''

Where as in version 0.9.0 comp[0].docstring() would return the following value:

sleep(seconds)\n\nDelay execution for a given number of seconds.  The argument may be\na floating point number for subsecond precision.'
bug

All 4 comments

I've tried to figure out what's wrong or what could have caused this.
The only related changeset i could find is the following one:
https://github.com/davidhalter/jedi/commit/6736b1a5ce56a6226f3c8fe13326ca3654995154

I've tried it a little bit more. Functions defined in pure Python modules are still working fine:

import jedi
source = '''
import re
re.search'''
script = jedi.Script(source, 3, len('re.search'), 'example.py')
comp = script.completions()
print(comp[0].docstring())

```
$ python test-jedi.py
search(pattern, string, flags=0)

Scan through string looking for a match to the pattern, returning
a match object, or None if no match was found.


Here's a quick hack for this case (time.sleep):
```Diff
diff --git a/jedi/api/classes.py b/jedi/api/classes.py
index c8c61250..b2d02503 100644
--- a/jedi/api/classes.py
+++ b/jedi/api/classes.py
@@ -727,7 +727,10 @@ class _Help(object):
         """
         node = self._get_node(fast)
         if node is None:
-            return ''
+            try:
+                return getattr(self._name.parent_context.obj, self._name.string_name).__doc__
+            except AttributeError:
+                return ''

         try:
             return node.raw_doc

I have no idea how the node should be found, so it's likely it won't work for other cases.

@yan12125 Thanks I'll try to revert to the latest version with that fix. This is a crucial feature for an IDE using Jedi, hence I have had to revert to using the older version.

Thanks for the report.

Was this page helpful?
0 / 5 - 0 ratings