Commit 1b145927 authored by Ezio Melotti's avatar Ezio Melotti

#17526: fix an IndexError raised while passing code without filename to...

#17526: fix an IndexError raised while passing code without filename to inspect.findsource().  Initial patch by Tyler Doyle.
parent 90984722
...@@ -550,7 +550,7 @@ def findsource(object): ...@@ -550,7 +550,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
......
...@@ -416,6 +416,12 @@ class TestBuggyCases(GetSourceBase): ...@@ -416,6 +416,12 @@ class TestBuggyCases(GetSourceBase):
finally: finally:
del linecache.cache[co.co_filename] del linecache.cache[co.co_filename]
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 TestNoEOL(GetSourceBase): class TestNoEOL(GetSourceBase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.tempdir = TESTFN + '_dir' self.tempdir = TESTFN + '_dir'
......
...@@ -5,8 +5,19 @@ Python News ...@@ -5,8 +5,19 @@ Python News
What's New in Python 3.3.2? What's New in Python 3.3.2?
=========================== ===========================
*Release date: XXXX-XX-XX*
*Not yet released, see sections below for changes released in 3.3.0* *Not yet released, see sections below for changes released in 3.3.0*
Core and Builtins
-----------------
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 3.3.1? What's New in Python 3.3.1?
=========================== ===========================
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment