MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / getfile

Function getfile

tools/python-3.11.9-amd64/Lib/inspect.py:892–918  ·  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

890 return '\n'.join(lines)
891
892def getfile(object):
893 """Work out which source or compiled file an object was defined in."""
894 if ismodule(object):
895 if getattr(object, '__file__', None):
896 return object.__file__
897 raise TypeError('{!r} is a built-in module'.format(object))
898 if isclass(object):
899 if hasattr(object, '__module__'):
900 module = sys.modules.get(object.__module__)
901 if getattr(module, '__file__', None):
902 return module.__file__
903 if object.__module__ == '__main__':
904 raise OSError('source code not available')
905 raise TypeError('{!r} is a built-in class'.format(object))
906 if ismethod(object):
907 object = object.__func__
908 if isfunction(object):
909 object = object.__code__
910 if istraceback(object):
911 object = object.tb_frame
912 if isframe(object):
913 object = object.f_code
914 if iscode(object):
915 return object.co_filename
916 raise TypeError('module, class, method, function, traceback, frame, or '
917 'code object was expected, got {}'.format(
918 type(object).__name__))
919
920def getmodulename(path):
921 """Return the module name for a given file, or None."""

Callers 5

_get_signatureMethod · 0.90
getsourcefileFunction · 0.85
getabsfileFunction · 0.85
findsourceFunction · 0.85
getframeinfoFunction · 0.85

Calls 10

ismoduleFunction · 0.85
isclassFunction · 0.85
ismethodFunction · 0.85
isfunctionFunction · 0.85
istracebackFunction · 0.85
isframeFunction · 0.85
iscodeFunction · 0.85
typeClass · 0.50
formatMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected