"assert" is good, but it is used as a guard frequently.
We can make such usage legal by adding a new syntax:
assert bool_expr, ExceptionType, True
suggest reasons:
1) even "__debug__" turn off, assert is working
assertion as guard.
2) to avoid boilerplate code
I write code like this:
if pred(....) or pred(....):
raise ValueError('pred(....) or pred(....)')
Simplifed:
assert pred(...), ValueError, True
# the above line will be printed when error.
# I need not to copy the condition!
3) future: "assert bool_expr, ET, False"
To aid static tool, like Proof System.
Better document.
For complicate algorithm,
I actually add a invariant outline comment
above every statement.
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/