comparison mercurial/thirdparty/attr/converters.py @ 34397:765eb17a7eb8

thirdparty: vendor attrs The attrs package allows defining namedtuple-like classes with no weird behavior and no runtime performance cost. This patch vendors in attrs 17.2.0. # no-check-commit Differential Revision: https://phab.mercurial-scm.org/D867
author Siddharth Agarwal <sid0@fb.com>
date Sun, 01 Oct 2017 04:14:16 -0700
parents
children e1c586b9a43c
comparison
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