Rename remaining validator/default decorator examples with unclear names (#544)
The documentation already explains well why validator or default decorated methods must not have the name of existing attributes (because they would be overridden). This replaces the last remaining examples not using the explicit explanatory name.
This commit is contained in:
parent
25a02bbc7b
commit
615054392a
|
@ -73,11 +73,11 @@ Core
|
||||||
... x = attr.ib()
|
... x = attr.ib()
|
||||||
... y = attr.ib()
|
... y = attr.ib()
|
||||||
... @x.validator
|
... @x.validator
|
||||||
... def name_can_be_anything(self, attribute, value):
|
... def _any_name_except_a_name_of_an_attribute(self, attribute, value):
|
||||||
... if value < 0:
|
... if value < 0:
|
||||||
... raise ValueError("x must be positive")
|
... raise ValueError("x must be positive")
|
||||||
... @y.default
|
... @y.default
|
||||||
... def name_does_not_matter(self):
|
... def _any_name_except_a_name_of_an_attribute(self):
|
||||||
... return self.x + 1
|
... return self.x + 1
|
||||||
>>> C(1)
|
>>> C(1)
|
||||||
C(x=1, y=2)
|
C(x=1, y=2)
|
||||||
|
|
|
@ -341,7 +341,7 @@ The method receives the partially initialized instance which enables you to base
|
||||||
... x = attr.ib(default=1)
|
... x = attr.ib(default=1)
|
||||||
... y = attr.ib()
|
... y = attr.ib()
|
||||||
... @y.default
|
... @y.default
|
||||||
... def name_does_not_matter(self):
|
... def _any_name_except_a_name_of_an_attribute(self):
|
||||||
... return self.x + 1
|
... return self.x + 1
|
||||||
>>> C()
|
>>> C()
|
||||||
C(x=1, y=2)
|
C(x=1, y=2)
|
||||||
|
|
Loading…
Reference in New Issue