code: def sanitize(type_repr: str):
      type_repr = re.sub(r"<class \'(.*)\'>", r"\1", type_repr)
      type_repr = type_repr.replace("typing.", "")
      type_repr = type_repr.replace("torch_sparse.tensor.", "")
      type_repr = type_repr.replace(
          "Adj", "Union[Tensor, SparseTensor]"
      )
  
      # Replace `Union[..., NoneType]` by `Optional[...]`.
      sexp = pp.nestedExpr(opener="[", closer="]")
      tree = sexp.parseString(
          f'[{type_repr.replace(",", " ")}]'
      ).asList()[0]
  
      def union_to_optional_(tree):
          for i in range(len(tree)):
              e, n = tree[i], tree[i + 1] if i + 1 < len(tree) else []
              if e == "Union" and n[-1] == "NoneType":
                  tree[i] = "Optional"
                  tree[i + 1] = tree[i + 1][:-1]
              elif e == "Union" and "NoneType" in n:
                  idx = n.index("NoneType")
                  n[idx] = [n[idx - 1]]
                  n[idx - 1] = "Optional"
              elif isinstance(e, list):
                  tree[i] = union_to_optional_(e)
          return tree
  
      tree = union_to_optional_(tree)
      type_repr = re.sub(r"\'|\"", "", str(tree)[1:-1]).replace(
          ", [", "["
      )
  
      return type_repr
  
file_path: AutoGL/autogl/module/nas/space/gasso_space/utils/typing.py
imports: import re
  import inspect
  import pyparsing
  from itertools import product
  from collections import OrderedDict
  from typing import Callable, Tuple, Dict, List
label_desc: Use image node_id 2 for calling a global function with example usage: sanitize(type_repr) and returns: type_repr, tree