Clarify that validators/converters only run on init

This commit is contained in:
Hynek Schlawack 2021-10-28 07:00:01 +02:00
parent 5c78fbc154
commit 95b70bde2e
1 changed files with 5 additions and 0 deletions

View File

@ -440,6 +440,9 @@ Therefore if you use ``@attr.s(auto_attribs=True)``, it is *not* enough to decor
...
TypeError: ("'x' must be <type 'int'> (got '42' that is a <type 'str'>).", Attribute(name='x', default=NOTHING, factory=NOTHING, validator=<instance_of validator for type <type 'int'>>, type=None, kw_only=False), <type 'int'>, '42')
Please note that if you use `attr.s` (and not `attr.define`) to define your class, validators only run on initialization by default.
This behavior can be changed using the ``on_setattr`` argument.
Check out `validators` for more details.
@ -458,6 +461,8 @@ This can be useful for doing type-conversions on values that you don't want to f
>>> o.x
1
Please note that converters only run on initialization.
Check out `converters` for more details.