From 2e2748aee3b704ef9022ce3d8bf70e676c07cf00 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 9 Feb 2019 13:34:48 +0100 Subject: [PATCH] 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 --- docs/init.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/init.rst b/docs/init.rst index 41a86ca7..85fcf39b 100644 --- a/docs/init.rst +++ b/docs/init.rst @@ -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