On 29 November 2017 at 02:03, Ivan Pozdeev via Python-ideas
<python-ideas@python.org> wrote:
> On 28.11.2017 16:36, Nick Coghlan wrote:
>> I'll make the same observation I usually do each time one of these
>> threads comes up:
>>
>> * I'm opposed to making assert substantially different from the way it
>> works now
>> * I'm in favour of adding a new "ensure()" builtin that encapsulates
>> the check-and-raise logic
>>
>> The reasons I prefer this approach:
>>
>> - assert is a statement *solely* so that the compiler can optimise it
>> out. If it's not optional,
>>    it doesn't need to be a statement any more
>
> Another benefit of a statement vs function is only evaluating the
> error-related arguments when there's an error

If you're worried about that level of micro-optimisation, it's
straightforward enough to write your own wrapper function that accepts
the components needed to build a suitably formatted message. There's
no need to make the builtin more complicated to cope with it (that
smooth transition from the builtin behaviour to customised behaviour
is one of the other advantages of using a plain function).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to