Clarify execution order in init (#488)

* Clarify execution order in init

Fixes #461

* Clarify attributes are processed in the order of declaration

* Simple past is good enough
This commit is contained in:
Hynek Schlawack 2019-02-09 13:34:48 +01:00 committed by GitHub
parent 87b2bb2e48
commit 2e2748aee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -350,6 +350,23 @@ If you need to set attributes on a frozen class, you'll have to resort to the :r
Note that you *must not* access the hash code of the object in ``__attrs_post__init__`` if ``cache_hash=True``.
Order of Execution
------------------
If present, the hooks are executed in the following order:
1. For each attribute, in the order it was declared:
a. default factory
b. converter
2. *all* validators
3. ``__attrs_post_init__``
Notably this means, that you can access all attributes from within your validators, but your converters have to deal with invalid values and have to return a valid value.
.. _`Wiki page`: https://github.com/python-attrs/attrs/wiki/Extensions-to-attrs
.. _`get confused`: https://github.com/python-attrs/attrs/issues/289
.. _`there is no such thing as a private argument`: https://github.com/hynek/characteristic/issues/6