summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorPhillip J. Eby <pje@telecommunity.com>2006-04-30 15:59:26 (GMT)
committerPhillip J. Eby <pje@telecommunity.com>2006-04-30 15:59:26 (GMT)
commit72ae6c80d489ea9d26958616d57cc37a5bd27d46 (patch)
tree9cfd6785d69266615656c2361e5f38bdef3102a9 /Lib/inspect.py
parentde9b624fb943295263f8140d9d2eda393348b8ec (diff)
downloadcpython-72ae6c80d489ea9d26958616d57cc37a5bd27d46.zip
cpython-72ae6c80d489ea9d26958616d57cc37a5bd27d46.tar.gz
cpython-72ae6c80d489ea9d26958616d57cc37a5bd27d46.tar.bz2
Fix infinite regress when inspecting <string> or <stdin> frames.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 2e4d987..4b2058e 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -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):