From: Phillip J. Eby Date: Sun, 30 Apr 2006 15:59:26 +0000 (+0000) Subject: Fix infinite regress when inspecting or frames. X-Git-Tag: v2.5b1~756 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72ae6c80d489ea9d26958616d57cc37a5bd27d46;p=python Fix infinite regress when inspecting or frames. --- diff --git a/Lib/inspect.py b/Lib/inspect.py index 2e4d987bd8..4b2058e437 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 - '' and '' 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):