On Fri, Jul 08, 2011 at 09:47 +0200, Maciej Fijalkowski wrote: > On Fri, Jul 8, 2011 at 1:49 AM, Alex Gaynor <alex.gay...@gmail.com> wrote: > > Hi all, > > I've now spoken with several developers about the object identity that > > arises out of hte new dict strategies, and all seem to think that the > > current implementation breaks Python's semantics, that is: > > x = 3 > > z = {x: None} > > assert next(iter(z)) is x > > will fail. The only solution I see to this that maintains the correct > > semantics in all cases is to specialize is/id() for primitive types. That > > is to say, all integers of any given value have the same id() and x is y is > > true. Doing x is y is true is easy, you simply have a multimethod which > > dispatches on the types and compares intval for W_IntObjects (objects of > > differing types can never have the same identity) however the question is > > what to use for id() that is unique, never changes for an int, and doesn't > > intersect with any other live object. In particular the last constraint is > > the most difficult I think. > > Alex > > >>> x = 3 > >>> x is 3 > True > >>> x = 1003 > >>> x is 1003 > False > >>>
I guess this is not what Alex means here. In CPython, PyPy (both 1.5 and trunk) you can do: >>> class A: pass >>> a=A() >>> next(iter({a: None})) is a True but not with ints on pypy-trunk >>> a=3 >>> next(iter({a: None})) is a False (it's true on pypy-1.5). IOW, i think the issue here is that iterating over keys of a dict usually gives the exact same ("is") objects in CPython whereas pypy trunk does not provide that at least for ints. best, holger > Stop relying on obscure details I think > _______________________________________________ > pypy-dev mailing list > pypy-dev@python.org > http://mail.python.org/mailman/listinfo/pypy-dev _______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev