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:
Oliver Bestwalter 2019-06-17 09:17:29 +02:00 committed by Hynek Schlawack
parent 25a02bbc7b
commit 615054392a
2 changed files with 3 additions and 3 deletions

View File

@ -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)

View File

@ -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)