<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 2 July 2014 08:36, Stefano Borini <span dir="ltr"><<a href="mailto:stefano.borini@ferrara.linux.it" target="_blank">stefano.borini@ferrara.linux.it</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Dear all,<br>
<br>
after the first mailing list feedback, and further private discussion with Joseph Martinot-Lagarde, I drafted a first iteration of a PEP for keyword arguments in indexing. The document is available here.<br>
<br>
<a href="https://github.com/stefanoborini/pep-keyword/blob/master/PEP-XXX.txt" target="_blank">https://github.com/<u></u>stefanoborini/pep-keyword/<u></u>blob/master/PEP-XXX.txt</a><br>
<br>
The document is not in final form when it comes to specifications. In fact, it requires additional discussion about the best strategy to achieve the desired result. Particular attention has been devoted to present alternative implementation strategies, their pros and cons. I will examine all feedback tomorrow morning European time (in approx 10 hrs), and apply any pull requests or comments you may have.<br>

<br>
When the specification is finalized, or this community suggests that the PEP is in a form suitable for official submission despite potential open issues, I will submit it to the editor panel for further discussion, and deploy an actual implementation according to the agreed specification for a working test run.<br>

<br>
I apologize for potential mistakes in the PEP drafting and submission process, as this is my first PEP.<br></blockquote><div><br></div><div>One option I don't see is to have a[b=1, c=2] be translated to a.__getitem__((slice('b', 1, None), slice['c', 2, None)) automatically. That completely takes care of backwards compatibility in __getitem__ (no change at all), and also deals with your issue with abusing slice objects:</div>
<div><br></div><div>a[K=1:10:2] -> a.__getitem__(slice('K', slice(1, 10, 2)))</div><div><br></div><div>And using that we can have an ordered dict "literal"</div><div><br></div><div><div>class OrderedDictLiteral(object):</div>
<div>    def __getitem__(self, t):</div><div>        try:</div><div>            i = iter(t)</div><div>        except TypeError:</div><div>            i = (t,)</div><div><br></div><div>        return collections.OrderedDict((s.start, s.stop) for s in i)</div>
<div><br></div><div>odict = OrderedDictLiteral()</div></div><div><br></div><div>o = odict[a=1, b='c']</div><div>print(o)  # prints OrderedDict([('a', 1), ('b', 'c')])</div><div><br></div><div>
On a related note, if we combined this with the idea that kwargs should be constructed using the type of the passed dict (i.e. if you pass an OrderedDict as **kwargs you get a new OrderedDict in the function) we could do:</div>
<div><br></div><div><div>kw = OrderedDictLiteral()<br></div></div><div><br></div><div><div>def f(**kw):</div><div>    print(kw)<br></div><div><br></div><div>f('a', 'b', **kw[c='d', e=2])</div></div>
<div><br></div><div>always resulting in:</div><div><br></div><div>{'c': 'd', 'e': 2}<br></div><div><br></div><div>Tim Delaney</div></div></div></div>