Quantcast
Channel: Best practice for using assert? - Stack Overflow
Viewing all articles
Browse latest Browse all 17

Answer by Lutz Prechelt for Best practice for using assert?

$
0
0

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.


Viewing all articles
Browse latest Browse all 17

Trending Articles