diff -r bf5a899a5d7c Lib/inspect.py --- a/Lib/inspect.py Sun Apr 12 17:56:34 2015 -0400 +++ b/Lib/inspect.py Mon Apr 13 12:39:31 2015 -0400 @@ -596,7 +596,7 @@ if hasattr(object, '__file__'): return object.__file__ raise TypeError('{!r} is a built-in class'.format(object)) - if ismethod(object): + while ismethod(object): object = object.__func__ if isfunction(object): object = object.__code__ @@ -772,7 +772,7 @@ else: raise OSError('could not find class definition') - if ismethod(object): + while ismethod(object): object = object.__func__ if isfunction(object): object = object.__code__ diff -r bf5a899a5d7c Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Sun Apr 12 17:56:34 2015 -0400 +++ b/Lib/test/test_inspect.py Mon Apr 13 12:39:31 2015 -0400 @@ -354,6 +354,11 @@ def test_getfile(self): self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__) + def test_getfile_nested_methodtype(self): + m1 = types.MethodType((lambda self: self), object()) + m2 = types.MethodType(m1, object()) + inspect.getsource(m2) + def test_getfile_class_without_module(self): class CM(type): @property @@ -497,6 +502,11 @@ self.assertRaises(IOError, inspect.findsource, co) self.assertRaises(IOError, inspect.getsource, co) + def test_findsource_nested_methodtype(self): + m1 = types.MethodType((lambda self: self), object()) + m2 = types.MethodType(m1, object()) + inspect.findsource(m2) + class TestNoEOL(GetSourceBase): def __init__(self, *args, **kwargs): self.tempdir = TESTFN + '_dir'