code: def is_optional_type(tp):
      
  
      if tp is type(None):
          return True
      elif is_union_type(tp):
          return any(is_optional_type(tt) for tt in get_args(tp, evaluate=True))
      else:
          return False
docs: Returns `True` if the type is `type(None)`, or is a direct `Union` to `type(None)`, such as `Optional[T]`.
  
      NOTE: this method inspects nested `Union` arguments but not `TypeVar` definitions (`bound`/`constraint`). So it
      will return `False` if
       - `tp` is a `TypeVar` bound, or constrained to, an optional type
       - `tp` is a `Union` to a `TypeVar` bound or constrained to an optional type,
       - `tp` refers to a *nested* `Union` containing an optional type or one of the above.
  
      Users wishing to check for optionality in types relying on type variables might wish to use this method in
      combination with `get_constraints` and `get_bound`