Skip to content

Commit

Permalink
fix: fast=True now supports all event listener forms
Browse files Browse the repository at this point in the history
  • Loading branch information
autumnjolitz committed Jul 30, 2024
1 parent 2aa3d03 commit 9bf8489
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions instruct/templates/macros.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9bf8489

Please sign in to comment.