mercurial/thirdparty/attr/converters.py
author Boris Feld <boris.feld@octobus.net>
Mon, 10 Dec 2018 10:21:08 +0100
changeset 40881 8695fbe17f7c
parent 34397 765eb17a7eb8
child 49643 e1c586b9a43c
permissions -rw-r--r--
tests: update network related errors for Debian 9 We have a CI job that runs the Mercurial tests in parallel. Some of the network related failures seems to be different on the environment. Oddly, those failures happens only when running the tests in parallel, not when running the test file only. I have no idea how to get the windows formatted message for the error, if someone could give me an hand, I will update this changeset with the value. Differential Revision: https://phab.mercurial-scm.org/D5401

"""
Commonly useful converters.
"""

from __future__ import absolute_import, division, print_function


def optional(converter):
    """
    A converter that allows an attribute to be optional. An optional attribute
    is one which can be set to ``None``.

    :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)

    return optional_converter