def is_optional_type(tp):
if tp is type(None):<EOL><INDENT>return True<EOL><DEDENT>elif is_union_type(tp):<EOL><INDENT>return any(is_optional_type(tt) for tt in get_args(tp, evaluate=True))<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>
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`