-
-
Notifications
You must be signed in to change notification settings - Fork 424
Closed
Description
Seems like attr.s-level on_setattr is applied to all attributes including inherited, but doesn't become a part of Attribute definition (to save memory in sa_attrs dictionary, as far as I understand):
import attr
@attr.s
class Parent:
a = attr.ib()
b = attr.ib(type=int, on_setattr=attr.setters.validate)
def print_fun(self, attr, value):
print(f'Setting {attr.name} to {value}')
return value
@attr.s(on_setatr=print_fun)
class Child(Parent):
c = attr.ib()
c = Child(1, 2, 3)
c.a = 100 # prints 'Setting a to 100'
print(attr.fields(Child).a.on_setattr) # prints None
@attr.s
class NextChild(Child):
pass
c = NextChild(1, 2, 3)
c.a = 100 # silently passesSo, class-level on_setattr is totally removed on inheritance. Is it expected behaviour?
Reactions are currently unavailable