Message310219
This proposal is an outcome of repeated requests on python-ideas that assert statements be made unconditional, so they can be legitimately used for parameter validation, rather than solely as a form of inline self-test.
Rather than changing the assert statement, an alternative option would be to provide a new builtin (suggested name: "ensure") that raises ValidationError (a new subclass of AssertionError) if the first argument is false.
As a function, the new builtin could accept parameters for:
- the message to be reported on failure
- the exception type to be raised on failure
And since it would only be a new builtin rather than a new keyword, existing uses of the name "ensure" would be unaffected (except to the extent that linters may start warning about shadowing a builtin).
(Since it's a suggestion for a new builtin, actually doing this would require a PEP, which I'm not planning to write, I just wanted to get the suggestion explicitly on the record rather than leaving it buried in mailing list archives) |
|
Date |
User |
Action |
Args |
2018-01-18 05:32:11 | ncoghlan | set | recipients:
+ ncoghlan |
2018-01-18 05:32:11 | ncoghlan | set | messageid: <1516253531.71.0.467229070634.issue32590@psf.upfronthosting.co.za> |
2018-01-18 05:32:11 | ncoghlan | link | issue32590 messages |
2018-01-18 05:32:11 | ncoghlan | create | |
|