[Python-checkins] cpython (merge 3.3 -> default): #17526: merge with 3.3.

ezio.melotti python-checkins at python.org
Sat Mar 30 04:19:41 CET 2013


http://hg.python.org/cpython/rev/8362fbb0ef42
changeset:   83009:8362fbb0ef42
parent:      83006:ae5c4a9118b8
parent:      83008:39e103c1577e
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sat Mar 30 05:19:06 2013 +0200
summary:
  #17526: merge with 3.3.

files:
  Lib/inspect.py           |  2 +-
  Lib/test/test_inspect.py |  6 ++++++
  Misc/NEWS                |  3 +++
  3 files changed, 10 insertions(+), 1 deletions(-)


diff --git a/Lib/inspect.py b/Lib/inspect.py
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -550,7 +550,7 @@
 
     file = getfile(object)
     sourcefile = getsourcefile(object)
-    if not sourcefile and file[0] + file[-1] != '<>':
+    if not sourcefile and file[:1] + file[-1:] != '<>':
         raise OSError('source code not available')
     file = sourcefile if sourcefile else file
 
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -416,6 +416,12 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -297,6 +297,9 @@
 Library
 -------
 
+- Issue #17526: fix an IndexError raised while passing code without filename to
+  inspect.findsource().  Initial patch by Tyler Doyle.
+
 - Issue #17540: Added style to formatter configuration by dict.
 
 - Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2.  Initial

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list