From 9bf84898095d3d2241b94801661811d12dc8ca70 Mon Sep 17 00:00:00 2001 From: Autumn Date: Tue, 30 Jul 2024 11:23:20 -0700 Subject: [PATCH] fix: ``fast=True`` now supports all event listener forms --- instruct/templates/macros.jinja | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/instruct/templates/macros.jinja b/instruct/templates/macros.jinja index eabe8e0..30ce0cf 100644 --- a/instruct/templates/macros.jinja +++ b/instruct/templates/macros.jinja @@ -24,22 +24,34 @@ def make_setter(type_def, fast, derived, type_restriction, coerce_types=(), coer assert type_restriction is not None if fast: - def _set_{{field_name}}(self, val: type_def) -> NoneType: + def _set_{{field_name}}(self, val: type_def) -> None: {%- if has_coercion %} if isinstance(val, coerce_types): val = coerce_func(val) {%- endif %} + assert isinstance(val, type_restriction) {%- if on_sets %} _old_value = self.{{field_name}} {%- endif %} - {{setter_variable_template|format(key=field_name)|indent(12)}} + {{ setter_variable_template|format(key=field_name)|indent(12) }} {%- if on_sets %} {%- for on_func_name in on_sets %} self.{{on_func_name}}(_old_value, val) {%- endfor %} {%- endif %} + {%- if on_sets_1 %} + {%- for on_func_name in on_sets_1 %} + self.{{on_func_name}}(val) + {%- endfor %} + {%- endif %} + {%- if on_sets_3 %} + {%- for on_func_name in on_sets_3 %} + self.{{on_func_name}}("{{field_name}}", _old_value, val) + {%- endfor %} + {%- endif %} + else: - def _set_{{field_name}}(self, val: type_def) -> NoneType: + def _set_{{field_name}}(self, val: type_def) -> None: try: wrong_type = isinstance(val, type_restriction) except TypeError: