object = object.f_code
if iscode(object):
return object.co_filename
- raise TypeError('{!r} is not a module, class, method, '
- 'function, traceback, frame, or code object'.format(object))
+ raise TypeError('module, class, method, function, traceback, frame, or '
+ 'code object was expected, got {}'.format(
+ type(object).__name__))
def getmodulename(path):
"""Return the module name for a given file, or None."""
with self.assertRaises(TypeError):
inspect.getfile(C)
+ def test_getfile_broken_repr(self):
+ class ErrorRepr:
+ def __repr__(self):
+ raise Exception('xyz')
+ er = ErrorRepr()
+ with self.assertRaises(TypeError):
+ inspect.getfile(er)
+
def test_getmodule_recursion(self):
from types import ModuleType
name = '__inspect_dummy'