code: def subs(task, key, val):
      """Perform a substitution on a task
  
      Examples
      --------
      >>> def inc(x):
      ...     return x + 1
  
      >>> subs((inc, 'x'), 'x', 1)  # doctest: +ELLIPSIS
      (<function inc at ...>, 1)
      """
      type_task = type(task)
      if not (
          type_task is tuple and task and callable(task[0])
      ):  # istask(task):
          try:
              if type_task is type(key) and task == key:
                  return val
          except Exception:
              pass
          if type_task is list:
              return [subs(x, key, val) for x in task]
          return task
      newargs = []
      hash_key = {key}
      for arg in task[1:]:
          type_arg = type(arg)
          if (
              type_arg is tuple and arg and callable(arg[0])
          ):  # istask(task):
              arg = subs(arg, key, val)
          elif type_arg is list:
              arg = [subs(x, key, val) for x in arg]
          else:
              try:
                  if arg in hash_key:  # Hash and equality match
                      arg = val
              except TypeError:  # not hashable
                  pass
          newargs.append(arg)
      return task[:1] + tuple(newargs)
  
imports: from __future__ import annotations
  from collections import defaultdict
  from collections.abc import Collection, Iterable, Mapping
  from typing import Any, Literal, TypeVar, cast, overload
  from dask.typing import Graph, Key, NoDefault, no_default
label_desc: Use image node_id 17 for calling a global function with example usage: subs(task, key, val) and returns: unknown, task, unknown, val