Mercurial > hg
annotate mercurial/thirdparty/attr/converters.py @ 40955:f6187e60f792
help: present boolean arguments as "--[no-]foo"
This should make it much more discoverable (we document it in `hg help
flags`, but most users don't think to look there).
Note that flags that default to None (and not False) will not get this
new presentation. We can change the defaults to False later for flags
where it makes sense (probably almost all boolean flags).
Differential Revision: https://phab.mercurial-scm.org/D5432
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 14 Dec 2018 13:44:46 -0800 |
parents | 765eb17a7eb8 |
children | e1c586b9a43c |
rev | line source |
---|---|
34397 | 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 |