<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 31, 2010, at 7:31 PM, Benjamin Peterson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Lie Ryan <lie.1296@...> writes:<br><blockquote type="cite">that their id() is expensive is implementation details, and the<br></blockquote><blockquote type="cite">developer of PyPy should solve that instead of adding a clutch to the<br></blockquote><blockquote type="cite">stdlib.<br></blockquote><br>The stdlib isn't just about CPython. We already have optimized primitives for<br>CPython, so I don't see why helping other implementations isn't a good cause.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><br></div><div>Benjamin, could you elaborate of several points that are unclear:</div><div><br></div><div>* If id() is expensive in PyPy, then how are they helped by the code in </div><div><a href="http://codespeak.net/svn/pypy/trunk/pypy/lib/identity_dict.py">http://codespeak.net/svn/pypy/trunk/pypy/lib/identity_dict.py</a></div><div>which uses id() for the gets and sets and contains?</div><div><br></div><div>* In the examples you posted (such as <a href="http://codespeak.net/svn/pypy/trunk/pypy/tool/algo/graphlib.py">http://codespeak.net/svn/pypy/trunk/pypy/tool/algo/graphlib.py</a> ),</div><div>it appears that PyPy already has an identity dict,  so how are they helped by adding one to the collections module?</div><div><br></div><div>* Most of the posted examples already work with regular dicts (which check identity before they check equality) -- don't the other implementations already implement regular dicts which need to have identity-implied-equality in order to pass the test suite?  I would expect the following snippet to work under all versions and implementations of Python:</div><div><br></div><div><div>    >>> class A: </div><div>    ...         pass</div><div>    >>> a = A()</div><div>    >>> d = {a: 10}</div><div>    >>> assert d[a] == 10   # uses a's identity for lookup</div><div><br></div><div>* Is the proposal something needed for all implementations or is it just an optimization for a particular, non-CPython implementation?</div><div><br></div><div><br></div><div>Raymond</div><div><br></div></div><div><br></div><div><br></div></body></html>