From dd2659d81e558825cb1579b08dc92bd8c04b2d74 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Wed, 13 Nov 2024 00:04:04 -0500 Subject: [PATCH 1/2] Fixed value check in property assignment --- src/travertino/declaration.py | 2 +- tests/test_declaration.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/travertino/declaration.py b/src/travertino/declaration.py index 91791af..9599ea6 100644 --- a/src/travertino/declaration.py +++ b/src/travertino/declaration.py @@ -148,7 +148,7 @@ def __set__(self, obj, value): value = self.validate(value) - if value != getattr(obj, f"_{self.name}", None): + if value != getattr(obj, f"_{self.name}", self.initial): setattr(obj, f"_{self.name}", value) obj.apply(self.name, value) diff --git a/tests/test_declaration.py b/tests/test_declaration.py index 753362a..c2f1414 100644 --- a/tests/test_declaration.py +++ b/tests/test_declaration.py @@ -317,6 +317,17 @@ def test_property_with_implicit_default(StyleClass): style.apply.assert_called_once_with("implicit", None) +@pytest.mark.parametrize("StyleClass", [Style, DeprecatedStyle]) +def test_set_initial_no_apply(StyleClass): + """If a property hasn't been set, assigning it its initial value shouldn't apply.""" + style = StyleClass() + + # 0 is the initial value + style.explicit_value = 0 + + style.apply.assert_not_called() + + @pytest.mark.parametrize("StyleClass", [Style, DeprecatedStyle]) def test_directional_property(StyleClass): style = StyleClass() From 236961fd47fbd42d370697604276a82f7696b7e4 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Wed, 13 Nov 2024 00:39:55 -0500 Subject: [PATCH 2/2] Added changenote --- changes/234.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/234.misc.rst diff --git a/changes/234.misc.rst b/changes/234.misc.rst new file mode 100644 index 0000000..d6d11e8 --- /dev/null +++ b/changes/234.misc.rst @@ -0,0 +1 @@ +Removed an unnecessary reapply when assigning to a previously unassigned property, if the value being assigned is the same as the property's initial value.