File: //usr/lib/python3/dist-packages/attr/__pycache__/converters.cpython-39.pyc
a
Pͣ_� � @ sN d Z ddlmZmZmZ ddlmZmZmZ g d�Z dd� Z
edfd d
�ZdS )z
Commonly useful converters.
� )�absolute_import�division�print_function� )�NOTHING�Factory�pipe)r �optional�default_if_nonec s � fdd�}|S )z�
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
c s | d u rd S � | �S �N� ��val�� converterr �1/usr/lib/python3/dist-packages/attr/converters.py�optional_converter s z$optional.<locals>.optional_converterr )r r r r r r s r Nc sv � t u r|du rtd��� t ur0|dur0td��|dur@t|�� t� t�rf� jrXtd��� fdd�}n� fdd�}|S )a�
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 `attr.Factory` is supported, however the ``takes_self`` option
is *not*.
:param callable factory: A callable that takes not 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 `attr.Factory` is passed with
``takes_self=True``.
.. versionadded:: 18.2.0
Nz(Must pass either `default` or `factory`.z5Must pass either `default` or `factory` but not both.z1`takes_self` is not supported by default_if_none.c s | d ur| S � � � S r )�factoryr
��defaultr r �default_if_none_converterG s z2default_if_none.<locals>.default_if_none_converterc s | d ur| S � S r r r
r r r r O s )r � TypeErrorr �
isinstanceZ
takes_self�
ValueError)r r r r r r r
$ s �
�r
)�__doc__Z
__future__r r r �_maker r r �__all__r r
r r r r �<module> s