MCPcopy
hub / github.com/scrapy/scrapy / walk_callable

Function walk_callable

scrapy/utils/misc.py:239–252  ·  view source on GitHub ↗

Similar to ``ast.walk``, but walks only function body and skips nested functions defined within the node.

(node: ast.AST)

Source from the content-addressed store, hash-verified

237
238
239def 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] = (

Callers 1

Calls 1

extendMethod · 0.45

Tested by

no test coverage detected