[pypy-dev] Object identity and dict strategies

Maciej Fijalkowski fijall at gmail.com
Fri Jul 8 09:47:04 CEST 2011


On Fri, Jul 8, 2011 at 1:49 AM, Alex Gaynor <alex.gaynor at 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
>>>

Stop relying on obscure details I think


More information about the pypy-dev mailing list