New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inspect.findsource raises IndexError #61935
Comments
Here is one way to reproduce this bug:
def func():
pass
def func():
pass
def newfunc():
pass
[..snip..] Note: A related but different issue is http://bugs.python.org/issue1218234. |
Can you explain what makes this one a different problem? It looks like the same one to me. Or is your intent in this issue just to avoid the exception? In that case it seems to me it would better to fix bpo-1218234 if we can. |
Right, this issue is about the IndexError. The current patch for bpo-1218234 doesn't solve this problem. You will still get IndexErrors, but you will get them when functions are removed rather than when functions are added. I think we should simply throw an IOError instead of an IndexError. This matches the docstring and prevents help() from blowing up after reloading a module. |
This issue appears implicated in https://bitbucket.org/pypa/setuptools/issue/201 |
I'm unable to reproduce it now. Has it been fixed? >>> import x
>>> help(x)
Help on module x: NAME FUNCTIONS FILE >>> from importlib import reload
>>> reload(x)
<module 'x' from 'C:\\Users\\User\\src\\cpython\\x.py'>
>>> help(x)
Help on module x: NAME FUNCTIONS newfunc() FILE |
Sorry, you're right - now the issue is when you remove functions from the module: >>> reload(x)
<module 'x' from 'C:\\Users\\User\\src\\cpython\\x.py'>
>>> help(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User\src\cpython\\lib\_sitebuiltins.py", line 103, in __call__
return pydoc.help(*args, **kwds)
File "C:\Users\User\src\cpython\lib\pydoc.py", line 2000, in __call__
self.help(request)
File "C:\Users\User\src\cpython\lib\pydoc.py", line 2059, in help
else: doc(request, 'Help on %s:', output=self._output)
File "C:\Users\User\src\cpython\lib\pydoc.py", line 1779, in doc
pager(render_doc(thing, title, forceload))
File "C:\Users\User\src\cpython\lib\pydoc.py", line 1772, in render_doc
return title % desc + '\n\n' + renderer.document(object, name)
File "C:\Users\User\src\cpython\lib\pydoc.py", line 472, in document
if inspect.ismodule(object): return self.docmodule(*args)
File "C:\Users\User\src\cpython\lib\pydoc.py", line 1273, in docmodule
contents.append(self.document(value, key, name))
File "C:\Users\User\src\cpython\lib\pydoc.py", line 474, in document
if inspect.isroutine(object): return self.docroutine(*args)
File "C:\Users\User\src\cpython\lib\pydoc.py", line 1510, in docroutine
doc = getdoc(object) or ''
File "C:\Users\User\src\cpython\lib\pydoc.py", line 187, in getdoc
result = _getdoc(object) or inspect.getcomments(object)
File "C:\Users\User\src\cpython\lib\inspect.py", line 882, in getcomments
lines, lnum = findsource(object)
File "C:\Users\User\src\cpython\lib\inspect.py", line 871, in findsource
if pat.match(lines[lnum]): break
IndexError: list index out of range |
Thanks for reporting this, Kyle! Thanks for the PR, Irit! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: