def _extract_immediate(node):
  """Extracts an immediate value from a node.

  Supported node types:
    prim::Constant
    prim::ListConstruct
  """
  # Constant
  if node.kind() == "prim::Constant":
    # Try to extract as different types.
    try:
      return node.t("value")
    except RuntimeError:
      pass
    try:
      return node.f("value")
    except RuntimeError:
      pass
    try:
      return node.i("value")
    except RuntimeError:
      pass
    try:
      return node.s("value")
    except RuntimeError:
      pass
    return None
  # List
  elif node.kind() == "prim::ListConstruct":
    return [_extract_immediate(i.node()) for i in node.inputs()]
  else:
    raise ValueError("Unrecognized immediate input node: {!r}".format(node))