Hopefully this wasn't proposed before.
@attr.s
class C(object):
x = attr.ib()
y = attr.ib()
@x.validator
def x_smaller_than_y(self, attribute, value):
if value >= self.y:
raise ValueError("'x' has to be smaller than 'y'!")
If you managed to guess what this does it means the syntax is intuitive enough :)
Similar syntax familiar from property.deleter and friends can also be useful for other parts, but for validators it feels like a natural fit (especially with the recent change to allow multiple validators).
Hopefully this wasn't proposed before.
If you managed to guess what this does it means the syntax is intuitive enough :)
Similar syntax familiar from
property.deleterand friends can also be useful for other parts, but for validators it feels like a natural fit (especially with the recent change to allow multiple validators).