Set a business rule like if x < 0 raise error
As far as I am aware, there is no general (implementation-independent) solution for this.
If, however, x
is an attribute of the objects of some class C
, it could be done by turning the plain attribute x
into a propertyx
that has not only a getter but also a setter:
https://docs.python.org/3/library/functions.html#property
The setter could then implement and enforce the business rule.