-
Notifications
You must be signed in to change notification settings - Fork 147
Closed
Description
I originally filed here: ipython/ipython#8671
If a script attempts to use inspect.getfile() on a class that was defined in a script file after set_trace() is called an exception is raised. Here's the traceback and the demo script.
I discovered that ipython is replacing sys.modules['main'] at some point (didn't get as far as pinpointing an exact line). This object ipython puts in there doesn't have attributes inspect is looking for which leads to the exception. It seems ipython could clean up after itself when set_trace() exits or copy those attributes to the replaced item.
I'd really like to get a work around so I can make a local modification until this fix goes out.
Version info
Python 2.7.10
pip freeze | grep ipython
ipython==3.2.1
pip freeze | grep ipdb
ipdb==0.8.1
Traceback
> /Users/username/folder/test.py(10)test()
9 ipdb.set_trace()
---> 10 inspect.getfile(self.__class__)
11
ipdb> c
E
======================================================================
ERROR: test (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_test.py", line 10, in test
inspect.getfile(self.__class__)
File "/Users/username/homebrew/Cellar/python/2.7.10_2/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 408, in getfile
raise TypeError('{!r} is a built-in class'.format(object))
TypeError: <module '__main__' (built-in)> is a built-in class
----------------------------------------------------------------------
Ran 1 test in 1.268s
FAILED (errors=1)
Script for reproduction
import inspect
import unittest
import ipdb
class Test(unittest.TestCase):
def test(self):
inspect.getfile(self.__class__)
ipdb.set_trace()
inspect.getfile(self.__class__)
def main():
unittest.main()
if __name__ == '__main__':
main()
Metadata
Metadata
Assignees
Labels
No labels