Similar to ``ast.walk``, but walks only function body and skips nested functions defined within the node.
(node: ast.AST)
| 237 | |
| 238 | |
| 239 | def walk_callable(node: ast.AST) -> Iterable[ast.AST]: |
| 240 | """Similar to ``ast.walk``, but walks only function body and skips nested |
| 241 | functions defined within the node. |
| 242 | """ |
| 243 | todo: deque[ast.AST] = deque([node]) |
| 244 | walked_func_def = False |
| 245 | while todo: |
| 246 | node = todo.popleft() |
| 247 | if isinstance(node, ast.FunctionDef): |
| 248 | if walked_func_def: |
| 249 | continue |
| 250 | walked_func_def = True |
| 251 | todo.extend(ast.iter_child_nodes(node)) |
| 252 | yield node |
| 253 | |
| 254 | |
| 255 | _generator_callbacks_cache: LocalWeakReferencedCache[Callable[..., Any], bool] = ( |
no test coverage detected