cpython: 50706164c38f (original) (raw)

Mercurial > cpython

changeset 88776:50706164c38f

inspect.getfile: Don't crash on classes without '__module__' attribute #20372 Some classes defined in C may not have the '__module__' attribute, so we now handle this case to avoid having unexepected AttributeError. [#20372]

Yury Selivanov yselivanov@sprymix.com
date Mon, 27 Jan 2014 13:24:56 -0500
parents dbad4564cd12
children fc32459495fc
files Lib/inspect.py Lib/test/test_inspect.py
diffstat 2 files changed, 14 insertions(+), 3 deletions(-)[+] [-] Lib/inspect.py 7 Lib/test/test_inspect.py 10

line wrap: on

line diff

--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -516,9 +516,10 @@ def getfile(object): return object.file raise TypeError('{!r} is a built-in module'.format(object)) if isclass(object):

--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -319,6 +319,16 @@ class TestRetrievingSourceCode(GetSource def test_getfile(self): self.assertEqual(inspect.getfile(mod.StupidGit), mod.file)

+ def test_getmodule_recursion(self): from types import ModuleType name = '__inspect_dummy'