Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/attr/setters.py
7762 views
# SPDX-License-Identifier: MIT12"""3Commonly used hooks for on_setattr.4"""56from __future__ import absolute_import, division, print_function78from . import _config9from .exceptions import FrozenAttributeError101112def pipe(*setters):13"""14Run all *setters* and return the return value of the last one.1516.. versionadded:: 20.1.017"""1819def wrapped_pipe(instance, attrib, new_value):20rv = new_value2122for setter in setters:23rv = setter(instance, attrib, rv)2425return rv2627return wrapped_pipe282930def frozen(_, __, ___):31"""32Prevent an attribute to be modified.3334.. versionadded:: 20.1.035"""36raise FrozenAttributeError()373839def validate(instance, attrib, new_value):40"""41Run *attrib*'s validator on *new_value* if it has one.4243.. versionadded:: 20.1.044"""45if _config._run_validators is False:46return new_value4748v = attrib.validator49if not v:50return new_value5152v(instance, attrib, new_value)5354return new_value555657def convert(instance, attrib, new_value):58"""59Run *attrib*'s converter -- if it has one -- on *new_value* and return the60result.6162.. versionadded:: 20.1.063"""64c = attrib.converter65if c:66return c(new_value)6768return new_value697071NO_OP = object()72"""73Sentinel for disabling class-wide *on_setattr* hooks for certain attributes.7475Does not work in `pipe` or within lists.7677.. versionadded:: 20.1.078"""798081