Skip to content

Commit eb7e57f

Browse files
committed
fix: Correct bug in class keyword argument fast=True, bump version to v0.0.11
1 parent e07105e commit eb7e57f

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

instruct/about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.10'
1+
__version__ = '0.0.11'

instruct/templates/macros.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def make_setter(type_def, fast, derived, type_restriction, coerce_types=(), coer
2727
if isinstance(val, coerce_types):
2828
val = coerce_func(val)
2929
{%- endif %}
30+
{%- if on_sets %}
31+
_old_value = self.{{field_name}}
32+
{%- endif %}
3033
{{setter_variable_template|format(key=field_name)|indent(12)}}
3134
{%- if on_sets %}
3235
{%- for on_func_name in on_sets %}

tests/test_atomic.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,21 @@ def test_reset():
157157
assert not t.is_dirty
158158

159159

160+
def test_fast_setter():
161+
class FastData(Base, fast=True):
162+
__slots__ = {
163+
'a': int,
164+
'bar': str
165+
}
166+
167+
@add_event_listener('a')
168+
def on_a_set(self, old, new):
169+
self.bar = str(new)
170+
171+
f = FastData(a=1)
172+
assert f.bar == '1'
173+
174+
160175
def test_getitem():
161176
class Foo(Base):
162177
__slots__ = {

0 commit comments

Comments
 (0)