X Tutup
Skip to content

Commit 8b4c0cc

Browse files
committed
Catch IndexError when calling inspect.getsourcelines() and pydoc.getdoc().
This closes issue bpython#94.
1 parent 21bf1e2 commit 8b4c0cc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

bpython/inspection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ def fixlongargs(f, argspec):
156156
keys = argspec[0][-len(values):]
157157
try:
158158
src = inspect.getsourcelines(f)
159-
except IOError:
159+
except (IOError, IndexError):
160+
# IndexError is raised in inspect.findsource(), can happen in
161+
# some situations. See issue #94.
160162
return
161163
signature = ''.join(src[0])
162164
kwparsed = parsekeywordpairs(signature)

bpython/repl.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,15 @@ def complete(self, tab=False):
534534
if not self.get_args():
535535
self.argspec = None
536536
elif self.current_func is not None:
537-
self.docstring = pydoc.getdoc(self.current_func)
538-
if not self.docstring:
537+
try:
538+
self.docstring = pydoc.getdoc(self.current_func)
539+
except IndexError:
539540
self.docstring = None
541+
else:
542+
# pydoc.getdoc() returns an empty string if no
543+
# docstring was found
544+
if not self.docstring:
545+
self.docstring = None
540546

541547
cw = self.cw()
542548
cs = self.current_string()

0 commit comments

Comments
 (0)
X Tutup