mirror of
https://github.com/python/cpython.git
synced 2025-09-24 01:13:22 +00:00
#17526: fix an IndexError raised while passing code without filename to inspect.findsource(). Initial patch by Tyler Doyle.
This commit is contained in:
parent
f03aab7e51
commit
e66e7de5d6
3 changed files with 10 additions and 1 deletions
|
@ -525,7 +525,7 @@ def findsource(object):
|
||||||
|
|
||||||
file = getfile(object)
|
file = getfile(object)
|
||||||
sourcefile = getsourcefile(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')
|
raise IOError('source code not available')
|
||||||
file = sourcefile if sourcefile else file
|
file = sourcefile if sourcefile else file
|
||||||
|
|
||||||
|
|
|
@ -404,6 +404,12 @@ class TestBuggyCases(GetSourceBase):
|
||||||
self.assertEqual(inspect.findsource(co), (lines,0))
|
self.assertEqual(inspect.findsource(co), (lines,0))
|
||||||
self.assertEqual(inspect.getsource(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):
|
class _BrokenDataDescriptor(object):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -12,6 +12,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #17526: fix an IndexError raised while passing code without filename to
|
||||||
|
inspect.findsource(). Initial patch by Tyler Doyle.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 2.7.4?
|
What's New in Python 2.7.4?
|
||||||
===========================
|
===========================
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue