diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 2 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 66d5186..9e928b2 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -525,7 +525,7 @@ def findsource(object): file = getfile(object) sourcefile = getsourcefile(object) - if not sourcefile and file[0] + file[-1] != '<>': + if not sourcefile and file[:1] + file[-1:] != '<>': raise IOError('source code not available') file = sourcefile if sourcefile else file diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 30b1556..04dcfe9 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -404,6 +404,12 @@ class TestBuggyCases(GetSourceBase): self.assertEqual(inspect.findsource(co), (lines,0)) self.assertEqual(inspect.getsource(co), lines[0]) + def test_findsource_without_filename(self): + for fname in ['', '<string>']: + co = compile('x=1', fname, "exec") + self.assertRaises(IOError, inspect.findsource, co) + self.assertRaises(IOError, inspect.getsource, co) + class _BrokenDataDescriptor(object): """ |