[Python-checkins] r83291 - python/branches/py3k/Lib/pdb.py

georg.brandl python-checkins at python.org
Fri Jul 30 20:08:12 CEST 2010


Author: georg.brandl
Date: Fri Jul 30 20:08:12 2010
New Revision: 83291

Log:
Fix source finding if the given frame is a module-level frame.

Modified:
   python/branches/py3k/Lib/pdb.py

Modified: python/branches/py3k/Lib/pdb.py
==============================================================================
--- python/branches/py3k/Lib/pdb.py	(original)
+++ python/branches/py3k/Lib/pdb.py	Fri Jul 30 20:08:12 2010
@@ -105,6 +105,15 @@
     fp.close()
     return answer
 
+def getsourcelines(obj):
+    lines, lineno = inspect.findsource(obj)
+    if inspect.isframe(obj) and lineno == 0 and \
+           obj.f_globals is obj.f_locals:
+        # must be a module frame: do not try to cut a block out of it
+        return lines, 0
+    elif inspect.ismodule(obj):
+        return lines, 0
+    return inspect.getblock(lines[lineno:]), lineno+1
 
 # Interaction prompt line will separate file and call info from code
 # text using value of line_prefix string.  A newline and arrow may
@@ -1048,7 +1057,7 @@
         filename = self.curframe.f_code.co_filename
         breaklist = self.get_file_breaks(filename)
         try:
-            lines, lineno = inspect.getsourcelines(self.curframe)
+            lines, lineno = getsourcelines(self.curframe)
         except IOError as err:
             self.error(err)
             return
@@ -1064,7 +1073,7 @@
         except:
             return
         try:
-            lines, lineno = inspect.getsourcelines(obj)
+            lines, lineno = getsourcelines(obj)
         except (IOError, TypeError) as err:
             self.error(err)
             return


More information about the Python-checkins mailing list