Debian Codegraph @

lib/ansible/module_utils/_internal/_stack.py

raw
1 from __future__ import annotations as _annotations
2
3 import inspect as _inspect
4 import typing as _t
5
6
7 def caller_frame() -> _inspect.FrameInfo | None:
8 """Return the caller stack frame, skipping any marked with the `_skip_stackwalk` local."""
9 _skip_stackwalk = True
10
11 return next(iter_stack(), None)
12
13
14 def iter_stack() -> _t.Generator[_inspect.FrameInfo]:
15 """Iterate over stack frames, skipping any marked with the `_skip_stackwalk` local."""
16 _skip_stackwalk = True
17
18 for frame_info in _inspect.stack():
19 if '_skip_stackwalk' in frame_info.frame.f_locals:
20 continue
21
22 yield frame_info