Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify execution order in init #488

Merged
merged 5 commits into from
Feb 9, 2019
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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