code: def remove_optional(annotation: type):
      """
      Optional[X] annotations are actually represented as Union[X, NoneType].
      For our purposes, the "Optional" part is not interesting, so here we
      throw it away.
      """
      origin = getattr(annotation, "__origin__", None)
      args = getattr(annotation, "__args__", ())
  
      if origin == Union:
          return Union[
              tuple([arg for arg in args if arg != type(None)])
          ]  # noqa: E721
      else:
          return annotation
  
imports: import collections.abc
  from copy import deepcopy
  from pathlib import Path
  from typing import Any, Callable, cast, Dict, Iterable, List, Mapping, Set, Tuple, Type, TypeVar, Union, Optional
  import inspect
  import logging
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.lazy import Lazy
  from allennlp.common.params import Params
label_desc: Use image node_id 5 for calling a global function with example usage: remove_optional(annotation) and returns: Union, annotation