Complementary groups
from hanna import ComplementaryGroup, Configurable, Integer
class Rectangle(Configurable):
size = ComplementaryGroup(
[Integer('width'), lambda height, area: area // height],
[Integer('height'), lambda width, area: area // width],
[Integer('area'), lambda width, height: width * height]
)
r = Rectangle(dict(width=2, height=3))
r.size # {'width': 2, 'height': 3, 'area': 6}
r = Rectangle(dict(width=2, area=6))
r.size # {'width': 2, 'height': 3, 'area': 6}
r = Rectangle(dict(height=3, area=6))
r.size # {'width': 2, 'height': 3, 'area': 6}Last updated