100def recordCall(callerFileOnly: bool) -> CallStack:
101 stack_frames_raw = inspect.stack()
102 first_real_frame = next(
103 (
104 i
105 for i, x in enumerate(stack_frames_raw)
106 if x.frame.f_globals.get("__package__") != __package__
107 ),
108 None,
109 )
110
111 stack_frames = stack_frames_raw[first_real_frame:]
112
113 if callerFileOnly:
114 caller_file = stack_frames[0].filename
115 stack_frames = [
116 frame for frame in stack_frames if frame.filename == caller_file
117 ]
118
119 call_locations = [
120 CallLocation(frame.filename, frame.lineno) for frame in stack_frames
121 ]
122
123 location = call_locations[0]
124 rest_of_stack = call_locations[1:]
125
126 return CallStack(location, rest_of_stack)
127
128