<div dir="ltr"><div>

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">> > Makes sense. However, couldn't you prevent that by giving with</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">> priority over the binding ? As in "(with simple_cm) as value", where</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">> > we consider the "as" as binding operator instead of part of the with</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">> > statement ? Sure, you could commit suicide by parenthesis, but by</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">> > default it'd do exactly what the "with simple_cm as value" currently</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">> > does. This does require use of as instead of :=, though. (which was</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">> > the point I was trying to make, apologies for the confusion)</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span></span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> Does "(with simple_cm) as value" means "with (simple_cm as value)"?</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> If so, it's impossible to let the priority of "with ... as ..." over `as` binding.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> This is the grammar  of current syntax related to with statement:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> with_stmt: 'with' with_item (',' with_item)*  ':' suite</span> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> with_item: test ['as' expr]</span><span> </span>    </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> If `as` binding could be used in a general expression, just as </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> `test` is the top of expression, an expression using `as` binding must be in the structure > `test`.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> In other words, if you write </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> with expr as name:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">>     # do stuff</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> Without doubt it's equivalent to `with (expr as name)`.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> Or you want to completely change the grammar design of CPython :)</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> thautwarm</div></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">Additionally, here is an evidence.</span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I've just had a look at<span> </span></span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;font-size:14px;background-color:rgb(255,255,255);float:none;display:inline">Chris Angelico's implementation about expression assignment, it's  cool, however the problem is still raised.</span> </span></div><div><span style="font-size:14px"><br></span></div><div><a href="https://github.com/Rosuav/cpython/blob/0f237048b7665720b5165a40de0ed601c1e82c39/Grammar/Grammar">https://github.com/Rosuav/cpython/blob/0f237048b7665720b5165a40de0ed601c1e82c39/Grammar/Grammar</a><br></div><div><br></div><div><span style="font-size:14px">`as` binding is added at line 111, obviously you cannot separate it from the `test` structure(because `test` is the top expr).</span></div><div><br></div><div><span style="font-size:14px">

<span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">testlist_comp: (test|star_expr) ( comp_for | 'as' NAME | (',' (test|star_expr))* [','] )</span>

<br></span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">It seems that if we're to support expression assignment, `as` binding should be declined.</span></div><div><span style="font-size:14px">To be honest I feel upset because I think `expr as name` is really cool and pythonic.</span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">thautwarm</span></div><div><span style="font-size:14px"><br></span><div class="gmail_extra"> <br><div class="gmail_quote">2018-04-13 1:35 GMT+08:00 Thautwarm Zhao <span dir="ltr"><<a href="mailto:yaoxiansamma@gmail.com" target="_blank">yaoxiansamma@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> Makes sense. However, couldn't you prevent that by giving with</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> priority over the binding ? As in "(with simple_cm) as value", where</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> we consider the "as" as binding operator instead of part of the with</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> statement ? Sure, you could commit suicide by parenthesis, but by</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> default it'd do exactly what the "with simple_cm as value" currently</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> does. This does require use of as instead of :=, though. (which was</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> the point I was trying to make, apologies for the confusion)</span>

<br><div><br></div><div>Does "(with simple_cm) as value" means "with (simple_cm as value)"?</div><div>If so, it's impossible to let the priority of "with ... as ..." over `as` binding.</div><div><br></div><div>This is the grammar  of current syntax related to with statement:</div><div><br></div><div>

<span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">with_stmt: 'with' with_item (',' with_item)*  ':' suite</span> </div><div>

<span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">with_item: test ['as' expr]</span>

 
  </div><div><br></div><div>If `as` binding could be used in a general expression, just as </div><div>`test` is the top of expression, an expression using `as` binding must be in the structure `test`.</div><div>In other words, if you write </div><div><br></div><div> with expr as name:</div><div>     # do stuff</div><div><br></div><div>Without doubt it's equivalent to `with (expr as name)`.</div><div><br></div><div>Or you want to completely change the grammar design of CPython :)</div><div><br></div><div>thautwarm</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="gmail-m_3975897234181991841h5">2018-04-12 21:41 GMT+08:00  <span dir="ltr"><<a href="mailto:python-ideas-request@python.org" target="_blank">python-ideas-request@python.o<wbr>rg</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="gmail-m_3975897234181991841h5">Send Python-ideas mailing list submissions to<br>
        <a href="mailto:python-ideas@python.org" target="_blank">python-ideas@python.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<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>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:python-ideas-request@python.org" target="_blank">python-ideas-request@python.or<wbr>g</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:python-ideas-owner@python.org" target="_blank">python-ideas-owner@python.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Python-ideas digest..."<br>
<br></div></div>Today's Topics:<br>
<br>
   1. Re: PEP 572: Assignment Expressions (post #4) (Chris Angelico)<br>
   2. Re: PEP 572: Assignment Expressions (post #4) (Chris Angelico)<br>
   3. Re: PEP 572: Assignment Expressions (post #4) (Nick Coghlan)<br>
   4. Re: PEP 572: Assignment Expressions (post #4) (Jacco van Dorp)<br>
   5. Re: PEP 572: Assignment Expressions (post #4) (Chris Angelico)<br>
<br><br>---------- 已转发邮件 ----------<br>From: Chris Angelico <<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>><br>To: python-ideas <<a href="mailto:python-ideas@python.org" target="_blank">python-ideas@python.org</a>><br>Cc: <br>Bcc: <br>Date: Thu, 12 Apr 2018 23:08:06 +1000<br>Subject: Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)<br>On Thu, Apr 12, 2018 at 9:09 PM, Paul Moore <<a href="mailto:p.f.moore@gmail.com" target="_blank">p.f.moore@gmail.com</a>> wrote:<br>
> On 11 April 2018 at 22:28, Chris Angelico <<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>> wrote:<br>
>> On Thu, Apr 12, 2018 at 1:22 AM, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>> wrote:<br>
>>> This argument will be strengthened by making the examples used in the<br>
>>> PEP itself more attractive, as well as proposing suitable additions to<br>
>>> PEP 8, such as:<br>
>>><br>
>>> 1. If either assignment statements or assignment expressions can be<br>
>>> used, prefer statements<br>
>>> 2. If using assignment expressions would lead to ambiguity about<br>
>>> execution order, restructure to use statements instead<br>
>><br>
>> Fair enough. Also adding that chained assignment expressions should<br>
>> generally be avoided.<br>
><br>
> Another one I think should be included (I'm a bit sad that it's not so<br>
> obvious that no-one would ever even think of it, but the current<br>
> discussion pretty much killed that hope for me).<br>
><br>
> * Assignment expressions should never be used standalone - assignment<br>
> statements should *always* be used in that case.<br>
<br>
That's covered by the first point. If it's a standalone statement,<br>
then the statement form could be used, ergo you should prefer the<br>
statement form.<br>
<br>
ChrisA<br>
<br>
<br><br>---------- 已转发邮件 ----------<br>From: Chris Angelico <<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>><br>To: python-ideas <<a href="mailto:python-ideas@python.org" target="_blank">python-ideas@python.org</a>><br>Cc: <br>Bcc: <br>Date: Thu, 12 Apr 2018 23:14:34 +1000<br>Subject: Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)<br>On Thu, Apr 12, 2018 at 7:21 PM, Kirill Balunov <<a href="mailto:kirillbalunov@gmail.com" target="_blank">kirillbalunov@gmail.com</a>> wrote:<br>
><br>
> I gain readability! I don't see any reason to use it in other contexts...<br>
> Because it makes the code unreadable and difficult to perceive while giving<br>
> not so much benefit.  I may be wrong, but so far I have not seen a single<br>
> example that at least slightly changed my mind.<br>
<br>
This is, in effect, your entire argument for permitting assignments<br>
only in certain contexts. "I can't think of any useful reason for<br>
doing this, so we shouldn't do it". But that means making the language<br>
grammar more complicated (both in the technical sense of the parser's<br>
definitions, and in the colloquial sense of how you'd explain Python<br>
to a new programmer), because there are these magic constructs that<br>
can be used anywhere in an expression, but ONLY if that expression is<br>
inside an if or while statement. You lose the ability to refactor your<br>
code simply to satisfy an arbitrary restriction to appease someone's<br>
feeling of "it can't be useful anywhere else".<br>
<br>
There are basically two clean ways to do this:<br>
<br>
1) Create actual syntax as part of the while statement, in the same<br>
way that the 'with EXPR as NAME:' statement does. This means you<br>
cannot put any additional operators after the 'as NAME' part. It's as<br>
much a part of the statement's syntax as the word 'in' is in a for<br>
loop.<br>
<br>
2) Make this a feature of expressions in general. Then they can be<br>
used anywhere that an expression can be.<br>
<br>
I've gone for option 2. If you want to push for option 1, go ahead,<br>
but it's a nerfed solution just because you personally cannot think of<br>
any good use for this.<br>
<br>
ChrisA<br>
<br>
<br><br>---------- 已转发邮件 ----------<br>From: Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>><br>To: Chris Angelico <<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>><br>Cc: python-ideas <<a href="mailto:python-ideas@python.org" target="_blank">python-ideas@python.org</a>><br>Bcc: <br>Date: Thu, 12 Apr 2018 23:19:59 +1000<br>Subject: Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)<br>On 12 April 2018 at 07:28, Chris Angelico <<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>> wrote:<br>
> On Thu, Apr 12, 2018 at 1:22 AM, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>> wrote:<br>
>>> Frequently Raised Objections<br>
>>> ============================<br>
>><br>
>> There needs to be a subsection here regarding the need to call `del`<br>
>> at class and module scope, just as there is for loop iteration<br>
>> variables at those scopes.<br>
><br>
> Hmm, I'm not sure I follow. Are you saying that this is an objection<br>
> to assignment expressions, or an objection to them not being<br>
> statement-local? If the latter, it's really more about "rejected<br>
> alternative proposals".<br>
<br>
It's both - accidentally polluting class and module namespaces is an<br>
argument against expression level assignments in general, and sublocal<br>
namespaces aimed to eliminate that downside.<br>
<br>
Since feedback on the earlier versions of the PEP has moved sublocal<br>
namespaces into the "rejected due to excessive conceptual complexity"<br>
box, that means accidental namespace pollution comes back as a<br>
downside that the PEP should mention.<br>
<br>
I don't think it needs to say much, just point out that they share the<br>
downside of regular for loops: if you use one at class or module<br>
scope, and don't want to export the name, you need to delete it<br>
explicitly.<br>
<br>
Cheers,<br>
Nick.<br>
<br>
-- <br>
Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>   |   Brisbane, Australia<br>
<br>
<br><br>---------- 已转发邮件 ----------<br>From: Jacco van Dorp <<a href="mailto:j.van.dorp@deonet.nl" target="_blank">j.van.dorp@deonet.nl</a>><br>To: python-ideas <<a href="mailto:python-ideas@python.org" target="_blank">python-ideas@python.org</a>><br>Cc: <br>Bcc: <br>Date: Thu, 12 Apr 2018 15:31:59 +0200<br>Subject: Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)<br>2018-04-12 15:02 GMT+02:00 Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>>:<br>
> On 12 April 2018 at 22:22, Jacco van Dorp <<a href="mailto:j.van.dorp@deonet.nl" target="_blank">j.van.dorp@deonet.nl</a>> wrote:<br>
>> I've looked through PEP 343, contextlib docs (<br>
>> <a href="https://docs.python.org/3/library/contextlib.html" rel="noreferrer" target="_blank">https://docs.python.org/3/libr<wbr>ary/contextlib.html</a> ), and I couldn't<br>
>> find a single case where "with (y := f(x))" would be invalid.<br>
><br>
> Consider this custom context manager:<br>
><br>
>     @contextmanager<br>
>     def simple_cm():<br>
>         yield 42<br>
><br>
> Given that example, the following code:<br>
><br>
>     with cm := simple_cm() as value:<br>
>         print(cm.func.__name__, value)<br>
><br>
> would print "'simple_cm 42", since the assignment expression would<br>
> reference the context manager itself, while the with statement binds<br>
> the yielded value.<br>
><br>
> Another relevant example would be `contextlib.closing`: that returns<br>
> the passed in argument from __enter__, *not* self.<br>
><br>
> And that's why earlier versions of PEP 572 (which used the "EXPR as<br>
> NAME" spelling) just flat out prohibited top level name binding<br>
> expressions in with statements: "with (expr as name):" and "with expr<br>
> as name:" were far too different semantically for the only syntactic<br>
> difference to be a surrounding set of parentheses.<br>
><br>
> Cheers,<br>
> Nick.<br>
<br>
Makes sense. However, couldn't you prevent that by giving with<br>
priority over the binding ? As in "(with simple_cm) as value", where<br>
we consider the "as" as binding operator instead of part of the with<br>
statement ? Sure, you could commit suicide by parenthesis, but by<br>
default it'd do exactly what the "with simple_cm as value" currently<br>
does. This does require use of as instead of :=, though. (which was<br>
the point I was trying to make, apologies for the confusion)<br>
<br>
<br><br>---------- 已转发邮件 ----------<br>From: Chris Angelico <<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>><br>To: python-ideas <<a href="mailto:python-ideas@python.org" target="_blank">python-ideas@python.org</a>><br>Cc: <br>Bcc: <br>Date: Thu, 12 Apr 2018 23:41:49 +1000<br>Subject: Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)<br>On Thu, Apr 12, 2018 at 11:31 PM, Jacco van Dorp <<a href="mailto:j.van.dorp@deonet.nl" target="_blank">j.van.dorp@deonet.nl</a>> wrote:<br>
> 2018-04-12 15:02 GMT+02:00 Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>>:<br>
>> On 12 April 2018 at 22:22, Jacco van Dorp <<a href="mailto:j.van.dorp@deonet.nl" target="_blank">j.van.dorp@deonet.nl</a>> wrote:<br>
>>> I've looked through PEP 343, contextlib docs (<br>
>>> <a href="https://docs.python.org/3/library/contextlib.html" rel="noreferrer" target="_blank">https://docs.python.org/3/libr<wbr>ary/contextlib.html</a> ), and I couldn't<br>
>>> find a single case where "with (y := f(x))" would be invalid.<br>
>><br>
>> Consider this custom context manager:<br>
>><br>
>>     @contextmanager<br>
>>     def simple_cm():<br>
>>         yield 42<br>
>><br>
>> Given that example, the following code:<br>
>><br>
>>     with cm := simple_cm() as value:<br>
>>         print(cm.func.__name__, value)<br>
>><br>
>> would print "'simple_cm 42", since the assignment expression would<br>
>> reference the context manager itself, while the with statement binds<br>
>> the yielded value.<br>
>><br>
>> Another relevant example would be `contextlib.closing`: that returns<br>
>> the passed in argument from __enter__, *not* self.<br>
>><br>
>> And that's why earlier versions of PEP 572 (which used the "EXPR as<br>
>> NAME" spelling) just flat out prohibited top level name binding<br>
>> expressions in with statements: "with (expr as name):" and "with expr<br>
>> as name:" were far too different semantically for the only syntactic<br>
>> difference to be a surrounding set of parentheses.<br>
>><br>
>> Cheers,<br>
>> Nick.<br>
><br>
> Makes sense. However, couldn't you prevent that by giving with<br>
> priority over the binding ? As in "(with simple_cm) as value", where<br>
> we consider the "as" as binding operator instead of part of the with<br>
> statement ? Sure, you could commit suicide by parenthesis, but by<br>
> default it'd do exactly what the "with simple_cm as value" currently<br>
> does. This does require use of as instead of :=, though. (which was<br>
> the point I was trying to make, apologies for the confusion)<br>
<br>
If you want this to be a generic name-binding operation, then no; most<br>
objects cannot be used as context managers. You'll get an exception if<br>
you try to use "with 1 as x:", for instance.<br>
<br>
As Nick mentioned, there are context managers that return something<br>
other than 'self', and for those, "with expr as name:" has an<br>
important meaning that cannot easily be captured with an assignment<br>
operator.<br>
<br>
ChrisA<br>
<br>
<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>
<br></blockquote></div><br></div>
</blockquote></div><br></div></div></div>