From 1a2959cfa80f43d9a250e6b7ee39cee51b7e8a57 Mon Sep 17 00:00:00 2001 From: "Phillip J. Eby" Date: Thu, 20 Jul 2006 15:54:16 +0000 Subject: Fix SF#1516184 (again) and add a test to prevent regression. (There was a problem with empty filenames still causing recursion) --- Lib/inspect.py | 5 +++-- Lib/test/test_inspect.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 311fe7e..dc2fa08 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -364,8 +364,9 @@ def getabsfile(object, _filename=None): The idea is for each object to have a unique origin, so this routine normalizes the result as much as possible.""" - return os.path.normcase( - os.path.abspath(_filename or getsourcefile(object) or getfile(object))) + if _filename is None: + _filename = getsourcefile(object) or getfile(object) + return os.path.normcase(os.path.abspath(_filename)) modulesbyfile = {} diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 912a24f..76f2566 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -187,6 +187,7 @@ class TestRetrievingSourceCode(GetSourceBase): exec "def x(): pass" in m.__dict__ self.assertEqual(inspect.getsourcefile(m.x.func_code), '') del sys.modules[name] + inspect.getmodule(compile('a=10','','single')) class TestDecorators(GetSourceBase): fodderFile = mod2 -- cgit v0.12