# Path: src/attr/_compat.py
# PY2 = sys.version_info[0] == 2
# 
# Path: src/attr/_make.py
# NOTHING = _Nothing()
# 
# class Factory(object):
#     """
#     Stores a factory callable.
# 
#     If passed as the default value to `attrs.field`, the factory is used to
#     generate a new value.
# 
#     :param callable factory: A callable that takes either none or exactly one
#         mandatory positional argument depending on *takes_self*.
#     :param bool takes_self: Pass the partially initialized instance that is
#         being initialized as a positional argument.
# 
#     .. versionadded:: 17.1.0  *takes_self*
#     """
# 
#     __slots__ = ("factory", "takes_self")
# 
#     def __init__(self, factory, takes_self=False):
#         """
#         `Factory` is part of the default machinery so if we want a default
#         value here, we have to implement it ourselves.
#         """
#         self.factory = factory
#         self.takes_self = takes_self
# 
#     def __getstate__(self):
#         """
#         Play nice with pickle.
#         """
#         return tuple(getattr(self, name) for name in self.__slots__)
# 
#     def __setstate__(self, state):
#         """
#         Play nice with pickle.
#         """
#         for name, value in zip(self.__slots__, state):
#             setattr(self, name, value)
# 
# def pipe(*converters):
#     """
#     A converter that composes multiple converters into one.
# 
#     When called on a value, it runs all wrapped converters, returning the
#     *last* value.
# 
#     Type annotations will be inferred from the wrapped converters', if
#     they have any.
# 
#     :param callables converters: Arbitrary number of converters.
# 
#     .. versionadded:: 20.1.0
#     """
# 
#     def pipe_converter(val):
#         for converter in converters:
#             val = converter(val)
# 
#         return val
# 
#     if not PY2:
#         if not converters:
#             # If the converter list is empty, pipe_converter is the identity.
#             A = typing.TypeVar("A")
#             pipe_converter.__annotations__ = {"val": A, "return": A}
#         else:
#             # Get parameter type.
#             sig = None
#             try:
#                 sig = inspect.signature(converters[0])
#             except (ValueError, TypeError):  # inspect failed
#                 pass
#             if sig:
#                 params = list(sig.parameters.values())
#                 if (
#                     params
#                     and params[0].annotation is not inspect.Parameter.empty
#                 ):
#                     pipe_converter.__annotations__["val"] = params[
#                         0
#                     ].annotation
#             # Get return type.
#             sig = None
#             try:
#                 sig = inspect.signature(converters[-1])
#             except (ValueError, TypeError):  # inspect failed
#                 pass
#             if sig and sig.return_annotation is not inspect.Signature().empty:
#                 pipe_converter.__annotations__[
#                     "return"
#                 ] = sig.return_annotation
# 
#     return pipe_converter


from ._compat import PY2
from ._make import NOTHING, Factory, pipe
    import inspect
    import typing
    return optional_converter


def default_if_none(default=NOTHING, factory=None):
    """
    A converter that allows to replace ``None`` values by *default* or the
    result of *factory*.

    :param default: Value to be used if ``None`` is passed. Passing an instance
       of `attrs.Factory` is supported, however the ``takes_self`` option
       is *not*.
    :param callable factory: A callable that takes no parameters whose result
       is used if ``None`` is passed.

    :raises TypeError: If **neither** *default* or *factory* is passed.
    :raises TypeError: If **both** *default* and *factory* are passed.
    :raises ValueError: If an instance of `attrs.Factory` is passed with
       ``takes_self=True``.

    .. versionadded:: 18.2.0
    """
    if default is NOTHING and factory is None:
        raise TypeError("Must pass either `default` or `factory`.")

    if default is not NOTHING and factory is not None:
        raise TypeError(
            "Must pass either `default` or `factory` but not both."
        )

    if factory is not None:

# Path: src/attr/_compat.py
# PY2 = sys.version_info[0] == 2
# 
# Path: src/attr/_make.py
# NOTHING = _Nothing()
# 
# class Factory(object):
#     """
#     Stores a factory callable.
# 
#     If passed as the default value to `attrs.field`, the factory is used to
#     generate a new value.
# 
#     :param callable factory: A callable that takes either none or exactly one
#         mandatory positional argument depending on *takes_self*.
#     :param bool takes_self: Pass the partially initialized instance that is
#         being initialized as a positional argument.
# 
#     .. versionadded:: 17.1.0  *takes_self*
#     """
# 
#     __slots__ = ("factory", "takes_self")
# 
#     def __init__(self, factory, takes_self=False):
#         """
#         `Factory` is part of the default machinery so if we want a default
#         value here, we have to implement it ourselves.
#         """
#         self.factory = factory
#         self.takes_self = takes_self
# 
#     def __getstate__(self):
#         """
#         Play nice with pickle.
#         """
#         return tuple(getattr(self, name) for name in self.__slots__)
# 
#     def __setstate__(self, state):
#         """
#         Play nice with pickle.
#         """
#         for name, value in zip(self.__slots__, state):
#             setattr(self, name, value)
# 
# def pipe(*converters):
#     """
#     A converter that composes multiple converters into one.
# 
#     When called on a value, it runs all wrapped converters, returning the
#     *last* value.
# 
#     Type annotations will be inferred from the wrapped converters', if
#     they have any.
# 
#     :param callables converters: Arbitrary number of converters.
# 
#     .. versionadded:: 20.1.0
#     """
# 
#     def pipe_converter(val):
#         for converter in converters:
#             val = converter(val)
# 
#         return val
# 
#     if not PY2:
#         if not converters:
#             # If the converter list is empty, pipe_converter is the identity.
#             A = typing.TypeVar("A")
#             pipe_converter.__annotations__ = {"val": A, "return": A}
#         else:
#             # Get parameter type.
#             sig = None
#             try:
#                 sig = inspect.signature(converters[0])
#             except (ValueError, TypeError):  # inspect failed
#                 pass
#             if sig:
#                 params = list(sig.parameters.values())
#                 if (
#                     params
#                     and params[0].annotation is not inspect.Parameter.empty
#                 ):
#                     pipe_converter.__annotations__["val"] = params[
#                         0
#                     ].annotation
#             # Get return type.
#             sig = None
#             try:
#                 sig = inspect.signature(converters[-1])
#             except (ValueError, TypeError):  # inspect failed
#                 pass
#             if sig and sig.return_annotation is not inspect.Signature().empty:
#                 pipe_converter.__annotations__[
#                     "return"
#                 ] = sig.return_annotation
# 
#     return pipe_converter


# Path: src/attr/converters.py
from ._compat import PY2
from ._make import NOTHING, Factory, pipe
    import inspect
    import typing

    return optional_converter


def default_if_none(default=NOTHING, factory=None):
    """
    A converter that allows to replace ``None`` values by *default* or the
    result of *factory*.

    :param default: Value to be used if ``None`` is passed. Passing an instance
       of `attrs.Factory` is supported, however the ``takes_self`` option
       is *not*.
    :param callable factory: A callable that takes no parameters whose result
       is used if ``None`` is passed.

    :raises TypeError: If **neither** *default* or *factory* is passed.
    :raises TypeError: If **both** *default* and *factory* are passed.
    :raises ValueError: If an instance of `attrs.Factory` is passed with
       ``takes_self=True``.

    .. versionadded:: 18.2.0
    """
    if default is NOTHING and factory is None:
        raise TypeError("Must pass either `default` or `factory`.")

    if default is not NOTHING and factory is not None:
        raise TypeError(
            "Must pass either `default` or `factory` but not both."
        )

    if factory is not None:

        default = Factory(factory)