Skip to content

is_contains_context_name

faststream.utils.ast.is_contains_context_name #

is_contains_context_name(scip_name, name)
Source code in faststream/utils/ast.py
def is_contains_context_name(scip_name: str, name: str) -> bool:
    stack = traceback.extract_stack()[-3]
    tree = read_source_ast(stack.filename)
    node = cast(Union[ast.With, ast.AsyncWith], find_ast_node(tree, stack.lineno))
    context_calls = get_withitem_calls(node)

    try:
        pos = context_calls.index(scip_name)
    except ValueError:
        pos = 1

    return name in context_calls[pos:]