Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
bugfix for on_setattr (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ authored Dec 14, 2022
1 parent 8a058cc commit 4e6b824
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tests/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def test_descriptor_metadata():
class WithSetAttr:
"""Modify the value before saving it."""

value = Descriptor(on_setattr=lambda self, value: value + 1)
value_frozen = Descriptor(frozen=True, on_setattr=lambda self, value: value + 1)
value = Descriptor(on_setattr=lambda value: value + 1)
value_frozen = Descriptor(frozen=True, on_setattr=lambda value: value + 1)


def test_with_setattr():
Expand Down
2 changes: 1 addition & 1 deletion zninit/descriptor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def __set__(self, instance, value):
if self._frozen.get(instance, False):
raise TypeError(f"Frozen attribute '{self.name}' can not be changed.")
if self.on_setattr is not None:
value = self.on_setattr(instance, value)
value = self.on_setattr(value)
if self.check_types:
typeguard.check_type(
argname=self.name, value=value, expected_type=self.annotation
Expand Down

0 comments on commit 4e6b824

Please sign in to comment.