mercurial/thirdparty/attr/converters.py
changeset 34397 765eb17a7eb8
child 49643 e1c586b9a43c
equal deleted inserted replaced
34396:9fb9f8440b71 34397:765eb17a7eb8
       
     1 """
       
     2 Commonly useful converters.
       
     3 """
       
     4 
       
     5 from __future__ import absolute_import, division, print_function
       
     6 
       
     7 
       
     8 def optional(converter):
       
     9     """
       
    10     A converter that allows an attribute to be optional. An optional attribute
       
    11     is one which can be set to ``None``.
       
    12 
       
    13     :param callable converter: the converter that is used for non-``None``
       
    14         values.
       
    15 
       
    16     ..  versionadded:: 17.1.0
       
    17     """
       
    18 
       
    19     def optional_converter(val):
       
    20         if val is None:
       
    21             return None
       
    22         return converter(val)
       
    23 
       
    24     return optional_converter