# 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
        values.

    .. versionadded:: 17.1.0
    """

    def optional_converter(val):
        if val is None:
            return None
        return converter(val)

    if not PY2:
        sig = None
        try:
            sig = inspect.signature(converter)
        except (ValueError, TypeError):  # inspect failed
            pass
        if sig:
            params = list(sig.parameters.values())
            if params and params[0].annotation is not inspect.Parameter.empty:
                optional_converter.__annotations__["val"] = typing.Optional[
                    params[0].annotation
                ]
            if sig.return_annotation is not inspect.Signature.empty:
                optional_converter.__annotations__["return"] = typing.Optional[
                    sig.return_annotation
                ]

    return optional_converter



# 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

        values.

    .. versionadded:: 17.1.0
    """

    def optional_converter(val):
        if val is None:
            return None
        return converter(val)

    if not PY2:
        sig = None
        try:
            sig = inspect.signature(converter)
        except (ValueError, TypeError):  # inspect failed
            pass
        if sig:
            params = list(sig.parameters.values())
            if params and params[0].annotation is not inspect.Parameter.empty:
                optional_converter.__annotations__["val"] = typing.Optional[
                    params[0].annotation
                ]
            if sig.return_annotation is not inspect.Signature.empty:
                optional_converter.__annotations__["return"] = typing.Optional[
                    sig.return_annotation
                ]

    return optional_converter



def default_if_none(default=NOTHING, factory=None):