<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:arial,sans-serif">On Tue, Oct 10, 2017 at 3:34 PM, Nick Coghlan </span><span dir="ltr" style="font-family:arial,sans-serif"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span><span style="font-family:arial,sans-serif"> wrote:</span><br></div><div class="gmail_extra"><div class="gmail_quote"><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"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-">On 10 October 2017 at 01:24, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br></span><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"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-m_1159243181157489497gmail-"><span class="gmail-">On Sun, Oct 8, 2017 at 11:46 PM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<br></span><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"><div class="gmail_extra"><div class="gmail_quote"><span><span class="gmail-">On 8 October 2017 at 08:40, Koos Zevenhoven <span dir="ltr"><<a href="mailto:k7hoven@gmail.com" target="_blank">k7hoven@gmail.com</a>></span> wrote:<br></span><span class="gmail-"><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 class="gmail-m_1159243181157489497gmail-m_920119363741997834m_6930246526210895346gmail-"></span><span class="gmail-m_1159243181157489497gmail-m_920119363741997834m_6930246526210895346gmail-"></span><div class="gmail_extra"><div class="gmail_quote"><div><div style="font-family:monospace,monospace">​​I do remember Yury mentioning that the first draft of PEP 550 captured something when the generator function was called. I think I started reading the discussions after that had already been removed, so I don't know exactly what it was. But I doubt that it was *exactly* the above, because PEP 550 uses set and get operations instead of "assignment contexts" like PEP 555 (this one) does. ​​</div></div></div></div></div></blockquote><div><br></div></span></span><span class="gmail-"><div>We didn't forget it, we just don't think it's very useful.<br clear="all"></div></span></div></div></div></blockquote><div><br></div></span><span class="gmail-"><div>I'm not sure I agree on the usefulness. Certainly a lot of the complexity of PEP 550 exists just to cater to Nathaniel's desire to influence what a generator sees via the context of the send()/next() call. I'm still not sure that's worth it. In 550 v1 there's no need for chained lookups.<br></div></span></div></div></div></blockquote><div><br></div>The compatibility concern is that we want developers of existing libraries to be able to transparently switch from using thread local storage to context local storage, and the way thread locals interact with generators means that decimal (et al) currently use the thread local state at the time when next() is called, *not* when the generator is created.</div></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">​If you want to keep those semantics in decimal, then you're already done.​</div><br></div><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 dir="ltr"><div class="gmail_extra"><div class="gmail_quote"></div><div class="gmail_quote">I like Yury's example for this, which is that the following two examples are currently semantically equivalent, and we want to preserve that equivalence:<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">    with decimal.localcontext() as ctx:</div><div class="gmail_quote">        ctc.prex = 30<br></div><div class="gmail_quote"><span class="gmail-">        for i in gen():<br>
           pass<br>
<br></span>    g = gen()<br><div class="gmail_quote">    with decimal.localcontext() as ctx:</div><div class="gmail_quote">        ctc.prex = 30<br></div><span class="gmail-">        for i in g:<br>
          pass</span></div><br></div><div class="gmail_extra"><br></div></div></blockquote><div><br></div><div class="gmail_default" style="font-family:monospace,monospace">​Generator functions aren't usually called `gen`.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Change that to​:</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">with decimal.localcontext() as ctx:</div><div class="gmail_default" style="font-family:monospace,monospace">    ctc.prex = 30</div><div class="gmail_default" style="font-family:monospace,monospace">    for val in values():</div><div class="gmail_default" style="font-family:monospace,monospace">        do_stuff_with(val)</div></div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_default" style="font-family:monospace,monospace">​# and​</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div></div><div class="gmail_default" style="font-family:monospace,monospace">​vals = values()​</div><br><div class="gmail_default" style="font-family:monospace,monospace">​with decimal.localcontext() as ctx:</div><div class="gmail_default" style="font-family:monospace,monospace">    ctc.prex = 30</div><div class="gmail_default" style="font-family:monospace,monospace">    for val in vals:</div><div class="gmail_default" style="font-family:monospace,monospace">        do_stuff_with(val)</div><div class="gmail_default" style="font-family:monospace,monospace">​</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">​I see no reason why these two should be equivalent.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">––Koos</div><br clear="all"><div><br></div>-- <br><div class="gmail_signature">+ Koos Zevenhoven + <a href="http://twitter.com/k7hoven" target="_blank">http://twitter.com/k7hoven</a> +</div>
</div></div>