Elias,<div>I'm a little confused about what you're suggesting. You want to have a Mapping that does not supply a keys method? What use case motivated your proposal?</div><div><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Sep 10, 2018, 7:04 PM Elias Tarhini <<a href="mailto:eltrhn@gmail.com">eltrhn@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="ltr"><div>This has been bouncing around in my head for a while regarding the requisite 
<span style="font-family:monospace,monospace">keys()</span> method on mappings:</div><div><br></div><div>How come the ** unpacking operator, a built-in language feature, relies on a non-dunder to operate?</div><div><br></div><div>To me, I mean to say, requiring that classes implement <span style="font-family:monospace,monospace">keys()</span> – a method whose name is totally undistinguished – in order to conform to the mapping protocol feels like a design running counter to Python's norm of using dunders for everything "hidden". I am not sure if it feels dirty to anybody else, however. Interestingly, the docs <a href="https://docs.python.org/3/reference/datamodel.html#object.__iter__" rel="noreferrer" target="_blank">already say</a> that <i>[f]or mappings, [<span style="font-family:monospace,monospace">__iter__()</span>] should iterate over the keys of the container</i>, but it of course is not enforced in any way at present.<br></div><div dir="auto"><br></div><div dir="auto">So, then — how about enforcing it? Should <span style="font-family:monospace,monospace">__iter__()</span><span style="font-family:sans-serif">, for the reasons above, replace the current purpose of </span><span style="font-family:monospace,monospace">keys()</span><span style="font-family:sans-serif"> in mappings?</span></div><div dir="auto"><font face="sans-serif"><br></font></div><div dir="auto"><font face="sans-serif">I'm</font> not properly equipped at the moment to mess around with CPython (sorry), but 
I assume at a minimum this would entail either replacing all instances of <span style="font-family:monospace,monospace">PyMapping_Keys()</span> with <span style="font-family:monospace,monospace">PyObject_GetIter()<font face="arial,helvetica,sans-serif"> or alternatively changing  <span style="font-family:monospace,monospace">PyMapping_Keys()</span> to call the latter.</font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif"><br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">Does it sound like a reasonable change overall?</font></span></div><div dir="auto"><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif"><br></font></span></div><div dir="auto"><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">Eli</font></span></div></div></div>
_______________________________________________<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/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div>