<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">[Barry Warsaw]</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks!  I thought it was cute.  It was just something that occurred to me as I was reviewing some existing code.  The intent wasn’t to use `subdirs` outside of the assert statement, but I’m warm to it because it means I don’t have to do wasted work outside of the assert statement, or repeat myself in the assert message part.<br></blockquote><div><br></div><div>Because the latter ("repeat myself") is probably more tempting, I'll just note that the "laziness" of using an assignment expression instead may well have nudged you toward writing _better_ code too.<br><br>

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   assert len(subdirs := list(path.iterdir())) == 0, subdirs</span>

<br><br>Assuming the result of list(path.iterdir()) can change over time (seems very likely),</div><div><br></div><div>

<span style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">   assert len(list(path.iterdir())) == 0, 

<span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">list(path.iterdir())<br></span></span><br>_could_ end up both triggering and displaying an empty list in the exception detail.  The assignment-expression version cannot.</div><div><br><br style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">

<br></div></div></div>