MCPcopy Index your code
hub / github.com/python/cpython / getmodulename

Function getmodulename

Lib/inspect.py:870–880  ·  view source on GitHub ↗

Return the module name for a given file, or None.

(path)

Source from the content-addressed store, hash-verified

868 type(object).__name__))
869
870def getmodulename(path):
871 """Return the module name for a given file, or None."""
872 fname = os.path.basename(path)
873 # Check for paths that look like an actual module file
874 suffixes = [(-len(suffix), suffix)
875 for suffix in importlib.machinery.all_suffixes()]
876 suffixes.sort() # try longest suffixes first, in case they overlap
877 for neglen, suffix in suffixes:
878 if fname.endswith(suffix):
879 return fname[:neglen]
880 return None
881
882def getsourcefile(object):
883 """Return the filename that can be used to locate an object's source.

Callers

nothing calls this directly

Calls 3

basenameMethod · 0.45
sortMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…