code: def optional(converter):
      """
      A converter that allows an attribute to be optional. An optional attribute
      is one which can be set to ``None``.
  
      Type annotations will be inferred from the wrapped converter's, if it
      has any.
  
      :param callable converter: the converter that is used for non-``None``
          values.
  
      .. versionadded:: 17.1.0
      """
  
      def optional_converter(val):
          if val is None:
              return None
          return converter(val)
  
      xtr = _AnnotationExtractor(converter)
  
      t = xtr.get_first_param_type()
      if t:
          optional_converter.__annotations__["val"] = typing.Optional[t]
  
      rt = xtr.get_return_type()
      if rt:
          optional_converter.__annotations__[
              "return"
          ] = typing.Optional[rt]
  
      return optional_converter
  
imports: import typing
  from ._compat import _AnnotationExtractor
  from ._make import NOTHING, Factory, pipe
label_desc: Use image node_id 1 for calling a global function with example usage: optional(converter) and returns: optional_converter, converter, None