MCPcopy Index your code
hub / github.com/RustPython/RustPython / getfile

Function getfile

Lib/inspect.py:818–844  ·  view source on GitHub ↗

Work out which source or compiled file an object was defined in.

(object)

Source from the content-addressed store, hash-verified

816
817
818def getfile(object):
819 """Work out which source or compiled file an object was defined in."""
820 if ismodule(object):
821 if getattr(object, '__file__', None):
822 return object.__file__
823 raise TypeError('{!r} is a built-in module'.format(object))
824 if isclass(object):
825 if hasattr(object, '__module__'):
826 module = sys.modules.get(object.__module__)
827 if getattr(module, '__file__', None):
828 return module.__file__
829 if object.__module__ == '__main__':
830 raise OSError('source code not available')
831 raise TypeError('{!r} is a built-in class'.format(object))
832 if ismethod(object):
833 object = object.__func__
834 if isfunction(object):
835 object = object.__code__
836 if istraceback(object):
837 object = object.tb_frame
838 if isframe(object):
839 object = object.f_code
840 if iscode(object):
841 return object.co_filename
842 raise TypeError('module, class, method, function, traceback, frame, or '
843 'code object was expected, got {}'.format(
844 type(object).__name__))
845
846def getmodulename(path):
847 """Return the module name for a given file, or None."""

Callers 4

getsourcefileFunction · 0.85
getabsfileFunction · 0.85
findsourceFunction · 0.85
getframeinfoFunction · 0.85

Calls 11

ismoduleFunction · 0.85
getattrFunction · 0.85
isclassFunction · 0.85
hasattrFunction · 0.85
ismethodFunction · 0.85
isfunctionFunction · 0.85
istracebackFunction · 0.85
isframeFunction · 0.85
iscodeFunction · 0.85
formatMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected