<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 17, 2018 at 1:50 AM, Serhiy Storchaka <span dir="ltr"><<a href="mailto:storchaka@gmail.com" target="_blank">storchaka@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Recently Barry shown an example:<br>
<br>
    assert len(subdirs := list(path.iterdir())) == 0, subdirs<br>
<br>
It looks awful to me. It looks even worse than using asserts for validating the user input. The assert has a side effect, and it depends on the interpreter option (-O). Even if subdirs is not used outside of the assert *now*, it is easy to introduce an error later, and it is hard to notice it if tests are not ran with the -O option regularly.<br>
<br>
Does PEP 572 encourages writing such code, discourages this, or completely forbids?<br></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">The PEP has no specific opinion except it is not forbidden.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Personally I like Barry's example just fine -- assuming `subdirs` is not used later, this feels like a good use case.<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>