Walk the stack and find the frame of the first caller not in this module.
()
| 54 | |
| 55 | |
| 56 | def _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 | |
| 74 | def from_package(package: types.ModuleType): |
no outgoing calls
no test coverage detected
searching dependent graphs…