L iTdZddlZddlmZddlmZmZmZmZgdZ dZ edfdZ d Z y) z Commonly useful converters. N)_AnnotationExtractor)NOTHING ConverterFactorypipe)default_if_noneoptionalrto_boolcXttrfd}nfd}t}|j}|r tj ||j d<|j}|r tj ||j d<ttrt|ddS|S)a_ A converter that allows an attribute to be optional. An optional attribute is one which can be set to `None`. Type annotations will be inferred from the wrapped converter's, if it has any. Args: converter (typing.Callable): the converter that is used for non-`None` values. .. versionadded:: 17.1.0 c|y|||SN)valinstfield converters U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/attr/converters.pyoptional_converterz$optional..optional_converter&s{S$. .c|y|Srr)rrs rrz$optional..optional_converter-s{S> !rrreturnT) takes_self takes_field) isinstancerrget_first_param_typetypingOptional__annotations__get_return_type)rrxtrtrts` rr r s)Y' / " y )C   "A4:OOA4F**51   B 7=r7J**84)Y'+$OO rctur| d}t|tur| d}t|| t|ttr jr d}t |fd}|Sfd}|S)a A converter that allows to replace `None` values by *default* or the result of *factory*. Args: default: Value to be used if `None` is passed. Passing an instance of `attrs.Factory` is supported, however the ``takes_self`` option is *not*. factory (typing.Callable): A callable that takes no parameters whose result is used if `None` is passed. Raises: TypeError: If **neither** *default* or *factory* is passed. TypeError: If **both** *default* and *factory* are passed. ValueError: If an instance of `attrs.Factory` is passed with ``takes_self=True``. .. versionadded:: 18.2.0 z(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,||SjSr)factoryrdefaults rdefault_if_none_converterz2default_if_none..default_if_none_converterls ??$ $rc||SSrrr's rr)z2default_if_none..default_if_none_converterts Nr)r TypeErrorrrr ValueError)r(r&msgr)s` rr r Bs4'go8ng'"5En'"'7#   ECS/ ! % %$   %$rcvt|tr|j}|dvry|dvryd|}t|)a Convert "boolean" strings (for example, from environment variables) to real booleans. Values mapping to `True`: - ``True`` - ``"true"`` / ``"t"`` - ``"yes"`` / ``"y"`` - ``"on"`` - ``"1"`` - ``1`` Values mapping to `False`: - ``False`` - ``"false"`` / ``"f"`` - ``"no"`` / ``"n"`` - ``"off"`` - ``"0"`` - ``0`` Raises: ValueError: For any other value. .. versionadded:: 21.3.0 )Ttruer"yesyon1rT)Ffalsefnonoff0rFzCannot convert value to bool: )rstrlowerr,)rr-s rr r }sG8#siik ;; == *3' 2C S/r) __doc__r_compatr_makerrrr__all__r r r rrrr@s7)44 *Z$T8%v%r