You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [2]: importattrIn [3]: @attr.s
...: ... classC(object):
...: ... x=attr.ib()
...: ... y=attr.ib()
...: ... @x.validator
...: ... defname_can_be_anything(self, attribute, value):
...: ... ifvalue<0:
...: ... raiseValueError("x must be positive")
...: ... @y.default
...: ... defname_does_not_matter(self):
...: ... returnself.x+1
...:
In [5]: c=C(1)
In [6]: c.x=-1
I would like the c.x = -1 to also get validated.
My use case at hand is invalidating a cache in case an attribute gets changed, and I've tried validator and convert for this, but both seem to only get applied at __init__ time?!
The text was updated successfully, but these errors were encountered:
This is related to #233. Long story short, when I’ve implemented validators, I didn’t want to fuzz with __setattr__ although I already had it working. That ship has sailed after we implemented frozen classes, but someone has to take the time to implement this whole thing properly (see my thoughts on #233).
Based on the doc example:
I would like the
c.x = -1
to also get validated.My use case at hand is invalidating a cache in case an attribute gets changed, and I've tried
validator
andconvert
for this, but both seem to only get applied at__init__
time?!The text was updated successfully, but these errors were encountered: