This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients ncoghlan
Date 2018-01-18.05:32:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1516253531.71.0.467229070634.issue32590@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2018-01-18 05:32:11ncoghlansetrecipients: + ncoghlan
2018-01-18 05:32:11ncoghlansetmessageid: <1516253531.71.0.467229070634.issue32590@psf.upfronthosting.co.za>
2018-01-18 05:32:11ncoghlanlinkissue32590 messages
2018-01-18 05:32:11ncoghlancreate