]> granicus.if.org Git - python/commitdiff
Fix infinite regress when inspecting <string> or <stdin> frames.
authorPhillip J. Eby <pje@telecommunity.com>
Sun, 30 Apr 2006 15:59:26 +0000 (15:59 +0000)
committerPhillip J. Eby <pje@telecommunity.com>
Sun, 30 Apr 2006 15:59:26 +0000 (15:59 +0000)
Lib/inspect.py

index 2e4d987bd8e59eb3edbcb82b5e88581faf6c0ecd..4b2058e4379c91534e54fe8eac7380004a07ef7e 100644 (file)
@@ -353,7 +353,13 @@ def getsourcefile(object):
         if 'b' in mode and string.lower(filename[-len(suffix):]) == suffix:
             # Looks like a binary file.  We want to only return a text file.
             return None
-    if os.path.exists(filename) or hasattr(getmodule(object), '__loader__'):
+    if os.path.exists(filename):
+        return filename
+    # Ugly but necessary - '<stdin>' and '<string>' mean that getmodule()
+    # would infinitely recurse, because they're not real files nor loadable
+    # Note that this means that writing a PEP 302 loader that uses '<'
+    # at the start of a filename is now not a good idea.  :(
+    if filename[:1]!='<' and hasattr(getmodule(object), '__loader__'):
         return filename
 
 def getabsfile(object):