<div dir="ltr">I think having a means for such validations separate from assertions would be helpful.<div><div>However, I agree with Steven that 'validate' would be a bad keyword choice.</div></div><div>Besides breaking compatibility with programs that use 'validate', it would break</div><div><a href="https://docs.python.org/3.6/library/wsgiref.html#module-wsgiref.validate">wsgiref.validate</a> in the standard library.</div><div><br></div></div><div hspace="streak-pt-mark" style="max-height:1px"><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=abmlrb2xhc3J2YW5kZXJob29mQGdtYWlsLmNvbQ%3D%3D&type=zerocontent&guid=bc684ba0-1fad-4fee-8e97-99fecc8e7a96"><font color="#ffffff" size="1">ᐧ</font></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 16, 2018 at 2:22 PM, Juancarlo Añez <span dir="ltr"><<a href="mailto:apalala@gmail.com" target="_blank">apalala@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Perhaps the OP can look into Python macro libraries to get the wanted syntax?<div><br></div><div><a href="https://github.com/lihaoyi/macropy" target="_blank">https://github.com/lihaoyi/<wbr>macropy</a><br></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Tue, Jan 16, 2018 at 2:35 PM, Paul Moore <span dir="ltr"><<a href="mailto:p.f.moore@gmail.com" target="_blank">p.f.moore@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 16 January 2018 at 17:36, Sylvain MARIE<br>
<<a href="mailto:sylvain.marie@schneider-electric.com" target="_blank">sylvain.marie@schneider-elect<wbr>ric.com</a>> wrote:<br>
> (trying with direct reply this time)<br>
<span>><br>
>> Why do you do this? What's the requirement for delaying evaluation of the condition?<br>
><br>
</span>> Thanks for challenging my poorly chosen examples :)<br>
><br>
> The primary requirement is about *catching* unwanted/uncontrolled/heteroge<wbr>nous exceptions happening in the underlying functions that are combined together to provide the validation means, so as to provide a uniform/consistent outcome however diverse the underlying functions are (they can return booleans or raise exceptions, or both).<br>
><br>
> In your proposal, if 'is_foo_compliant' raises an exception, it will not be caught by 'assert_valid', therefore the ValidationError will not be raised. So this is not what I want as an application developer.<br>
<br>
Ah, OK. But nothing in your proposal for a new statement suggests you<br>
wanted that, and assert doesn't work like that, so I hadn't realised<br>
that's what you were after.<br>
<br>
You could of course simply do:<br>
<br>
def assert_valid(expr, help_msg):<br>
# Catch exceptions in expr() as you see fit<br>
if not expr():<br>
raise ValidationError(help_msg)<br>
<br>
assert_valid(lambda: 0 <= surf < 10000 and is_foo_compliant(surf),<br>
<span> help_msg="surface should be 0=<x<10000 or foo compliant")<br>
<br>
</span>No need for a whole expression language :-)<br>
<div class="m_-333433189689645131HOEnZb"><div class="m_-333433189689645131h5"><br>
Paul<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div class="m_-333433189689645131gmail_signature" data-smartmail="gmail_signature"><span style="color:rgb(0,102,0)">Juancarlo </span><b style="color:rgb(0,102,0)">Añez</b></div>
</font></span></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br></div>