From fddba95ad34663296e8284bbcab0281d2bd45da7 Mon Sep 17 00:00:00 2001 From: hugsy Date: Mon, 22 Apr 2024 13:27:19 -0700 Subject: [PATCH] let `ValidationError` exception propagate on setting check --- gef.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/gef.py b/gef.py index c5e151a44..e78c20343 100644 --- a/gef.py +++ b/gef.py @@ -10989,8 +10989,9 @@ def __setitem__(self, name: str, value: Any) -> None: if not isinstance(setting, GefSetting): raise TypeError new_value = setting.type(value) dbg(f"in __invoke_changed_hooks(\"{name}\"), {setting.value=} -> {new_value=}, changing={bool(setting.value != new_value)}") - if self.__invoke_changed_hooks(setting, new_value): - setting.value = new_value + self.__invoke_changed_hooks(setting, new_value) + self.__invoke_write_hooks(setting, new_value) + setting.value = new_value return # if not, assert `value` is a GefSetting, then insert it @@ -10999,8 +11000,8 @@ def __setitem__(self, name: str, value: Any) -> None: if not value.description: raise AttributeError("Invalid description") setting = value value = setting.value - if self.__invoke_write_hooks(setting, value): - super().__setitem__(name, setting) + self.__invoke_write_hooks(setting, value) + super().__setitem__(name, setting) return def __delitem__(self, name: str) -> None: @@ -11014,26 +11015,16 @@ def __invoke_read_hooks(self, setting: GefSetting) -> None: callback() return - def __invoke_changed_hooks(self, setting: GefSetting, new_value: Any) -> bool: + def __invoke_changed_hooks(self, setting: GefSetting, new_value: Any) -> None: old_value = setting.value if old_value == new_value: - return True + return for callback in setting.hooks["on_changed"]: - try: - callback(old_value, new_value) - except ValidationError as e: - warn(f"Failed to validate new value (reason: {e}), discarding value") - return False - return True + callback(old_value, new_value) - def __invoke_write_hooks(self, setting: GefSetting, new_value: Any) -> bool: + def __invoke_write_hooks(self, setting: GefSetting, new_value: Any) -> None: for callback in setting.hooks["on_write"]: - try: - callback(new_value) - except ValidationError as e: - warn(f"Failed to validate new value (reason: {e}), discarding value") - return False - return True + callback(new_value) class GefSessionManager(GefManager):