Skip to main content

python_lambdas_below_statement_boundary

Function python_lambdas_below_statement_boundary 

Source
pub fn python_lambdas_below_statement_boundary(
    node: &Node<'_>,
    ancestors: Ancestors<'_, '_>,
) -> usize
Expand description

How many lambdas enclose node below its nearest statement boundary — an expression_list, if, for or while — the count node.count_specific_ancestors::<PythonCode>(ancestors, python_is_lambda, boundary) takes.

That climb runs to the root where no boundary is near — a boolean operator in each level of a nested list — and was quadratic in depth asked of every such operator (#1767). Under a walk that lent a FoldCache the count is folded down the chain instead, each ancestor once per walk. The fold’s state is a u8; past 254 lambdas it saturates and the exact climb answers, so the count is exact at every depth and only a lambda nest that deep pays the climb.