File: _stack.py

package info (click to toggle)
ansible-core 2.19.0~beta6-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,628 kB
  • sloc: python: 180,313; cs: 4,929; sh: 4,601; xml: 34; makefile: 21
file content (22 lines) | stat: -rw-r--r-- 630 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from __future__ import annotations as _annotations

import inspect as _inspect
import typing as _t


def caller_frame() -> _inspect.FrameInfo | None:
    """Return the caller stack frame, skipping any marked with the `_skip_stackwalk` local."""
    _skip_stackwalk = True

    return next(iter_stack(), None)


def iter_stack() -> _t.Generator[_inspect.FrameInfo]:
    """Iterate over stack frames, skipping any marked with the `_skip_stackwalk` local."""
    _skip_stackwalk = True

    for frame_info in _inspect.stack():
        if '_skip_stackwalk' in frame_info.frame.f_locals:
            continue

        yield frame_info