summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-03-30 05:17:24 +0200
committerEzio Melotti <ezio.melotti@gmail.com>2013-03-30 05:17:24 +0200
commit1b145927d725b136b987df220dff0ec7529b6f29 (patch)
treea597728e07ca0af44f923c7f056aec396f61e784
parent9098472299a18471f29b3ed471376be2d29178be (diff)
downloadcpython-git-1b145927d725b136b987df220dff0ec7529b6f29.tar.gz
#17526: fix an IndexError raised while passing code without filename to inspect.findsource(). Initial patch by Tyler Doyle.
-rw-r--r--Lib/inspect.py2
-rw-r--r--Lib/test/test_inspect.py6
-rw-r--r--Misc/NEWS11
3 files changed, 18 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 7a7bb91b1b..7834d12ea7 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -550,7 +550,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 6e3f04e68a..9f5e93b0c7 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -416,6 +416,12 @@ class TestBuggyCases(GetSourceBase):
finally:
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):
def __init__(self, *args, **kwargs):
self.tempdir = TESTFN + '_dir'
diff --git a/Misc/NEWS b/Misc/NEWS
index 8c016a4c80..c3e9ef2fa7 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -5,8 +5,19 @@ Python News
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*
+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?
===========================