diff --git a/changes/239.misc.rst b/changes/239.misc.rst new file mode 100644 index 0000000..804c503 --- /dev/null +++ b/changes/239.misc.rst @@ -0,0 +1 @@ +The order in which attributes are primed in ``Node.__init__`` has been altered, so that ``.parent`` is available when a style is applied. diff --git a/src/travertino/node.py b/src/travertino/node.py index b0d50d5..1510bc7 100644 --- a/src/travertino/node.py +++ b/src/travertino/node.py @@ -1,5 +1,10 @@ class Node: def __init__(self, style, applicator=None, children=None): + # Parent needs to be primed before style is (potentially) applied with + # assignment of applicator. + self._parent = None + self._root = None + # Explicitly set the internal attribute first, since the setter for style will # access the applicator property. self._applicator = None @@ -7,8 +12,6 @@ def __init__(self, style, applicator=None, children=None): self.style = style self.applicator = applicator - self._parent = None - self._root = None if children is None: self._children = None else: