<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Apr 29, 2018 at 9:28 PM, Tim Peters <span dir="ltr"><<a href="mailto:tim.peters@gmail.com" target="_blank">tim.peters@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>>]<br>
<span class="">> Ooops. My proof [of] anti-concept has a flaw.  It only "shadows" names that<br>
> already exist.  Presumably that's the wrong idea, but it's easy enough to<br>
> change if desired.<br></span></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">        with sublocal(a=6):<br>
            g("first in block")<br>
            a = 5<br>
            g("set a to 5")<br>
            b = 19<br>
            g("set b to 19")<br>
        g("after")<br><br>
Worm around that too, then going back to the example at the top, if<br>
the manager's<br>
<br>
        locals().update(_locals)<br>
<br>
had the intended effect, it would end up restoring `b` to 2 too, yes?<br>
The only names that "should be" restored are the names in the `kws`<br>
dict.<br></blockquote><div><br></div><div>Actually, that wasn't my intention.  As I imagined the semantics, I wanted a context manager that restored the "outside" context for anything defined "inside" the context.  Allowing keyword arguments was just an extra "convenience" that was meant to be equivalent to defining/overwriting variables inside the body.  So these would be equivalent:</div><div><br></div><div>## 1</div><div>with sublocal():</div><div>    a = 1</div><div>    b = 2</div><div>    x = a + b</div><div># a, b now have their old values again</div><div><br></div><div>## 2</div><div><div 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">with sublocal(a=1, b=2):</div><div 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">    x = a + b<br></div><div 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"># a, b now have their old values again</div><div><br></div><div>## 3</div>with sublocal(a=1):</div><div>    b = 2</div><div>    x = a + b<br class="gmail-Apple-interchange-newline"><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"># a, b now have their old values again</span><br></div><div><br></div><div>I knew I was ignoring nonlocals and nested function scopes.  But just trying something really simple that looks like the un-proposal in some cases.  Maybe there's no way in pure-Python to deal with the edge cases though.</div><div><br></div></div>
</div></div>