Set of functions contained within nested task Examples -------- >>> inc = lambda x: x + 1 >>> add = lambda x, y: x + y >>> mul = lambda x, y: x * y >>> task = (add, (mul, 1, 2), (inc, 3)) # doctest: +SKIP >>> functions_of(task) # doctest: +SKIP set([add, mul, inc])
(task)
| 376 | |
| 377 | |
| 378 | def functions_of(task): |
| 379 | """Set of functions contained within nested task |
| 380 | |
| 381 | Examples |
| 382 | -------- |
| 383 | >>> inc = lambda x: x + 1 |
| 384 | >>> add = lambda x, y: x + y |
| 385 | >>> mul = lambda x, y: x * y |
| 386 | >>> task = (add, (mul, 1, 2), (inc, 3)) # doctest: +SKIP |
| 387 | >>> functions_of(task) # doctest: +SKIP |
| 388 | set([add, mul, inc]) |
| 389 | """ |
| 390 | funcs = set() |
| 391 | |
| 392 | work = [task] |
| 393 | sequence_types = {list, tuple} |
| 394 | |
| 395 | while work: |
| 396 | new_work = [] |
| 397 | for task in work: |
| 398 | if type(task) in sequence_types: |
| 399 | if istask(task): |
| 400 | funcs.add(unwrap_partial(task[0])) |
| 401 | new_work.extend(task[1:]) |
| 402 | else: |
| 403 | new_work.extend(task) |
| 404 | work = new_work |
| 405 | |
| 406 | return funcs |
| 407 | |
| 408 | |
| 409 | def default_fused_keys_renamer(keys, max_fused_key_length=120): |