Skip to content

Commit

Permalink
Clarify that validators/converters only run on init
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Oct 28, 2021
1 parent 5c78fbc commit 95b70bd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand All @@ -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.


Expand Down

0 comments on commit 95b70bd

Please sign in to comment.