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

Function _infer_caller

Lib/importlib/resources/_common.py:56–71  ·  view source on GitHub ↗

Walk the stack and find the frame of the first caller not in this module.

()

Source from the content-addressed store, hash-verified

54
55
56def _infer_caller():
57 """
58 Walk the stack and find the frame of the first caller not in this module.
59 """
60
61 def is_this_file(frame_info):
62 return frame_info.filename == stack[0].filename
63
64 def is_wrapper(frame_info):
65 return frame_info.function == 'wrapper'
66
67 stack = inspect.stack()
68 not_this_file = itertools.filterfalse(is_this_file, stack)
69 # also exclude 'wrapper' due to singledispatch in the call stack
70 callers = itertools.filterfalse(is_wrapper, not_this_file)
71 return next(callers).frame
72
73
74def from_package(package: types.ModuleType):

Callers 1

_Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…