]> granicus.if.org Git - python/commitdiff
#17526: fix an IndexError raised while passing code without filename to inspect.finds...
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 30 Mar 2013 03:17:24 +0000 (05:17 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 30 Mar 2013 03:17:24 +0000 (05:17 +0200)
Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS

index 7a7bb91b1be84c5594278934c714370ee91a6a9c..7834d12ea7d04419df27aa60512e24e94c23aa77 100644 (file)
@@ -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
 
index 6e3f04e68a0d37a019e9a2768fdb0472d69d4887..9f5e93b0c7fb4663847a970f360743d2149260a3 100644 (file)
@@ -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'
index 8c016a4c80d95d2be8d32143185d39ad74e4ca44..c3e9ef2fa747358848184dd932eb212f55a79f46 100644 (file)
--- 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?
 ===========================