On 1/24/2020 7:09 AM, Steven D'Aprano wrote:
On Fri, Jan 24, 2020 at 05:45:35AM -0500, Terry Reedy wrote:
On 1/24/2020 3:36 AM, Victor Stinner wrote:

CPython current behavior rely on the fact that it's possible to get
the memory address of an object.

No, this behavior relies on the language specification that all objects
have temporally unique integer ids that can be compared with 'is'.

I don't think that it should be part of Python language specification,
but seen as a CPython implementation detail.

Ids are a language feature; ids being addresses is a CPython detail, but
this detail is not relevant to equality comparison of items within
containers.

Thanks Terry for raising this. Of course CPython can optimize identity
tests by checking for the same memory address, and *memory address* is
an implementation-detail of object identity.

Any Python implementation ought to have a sense of object identity,
however it is implemented or emulated. For instance, both Java and .Net
have compacting memory models, which means objects can move around in
memory and there's no well-defined "memory address", but both have to be
able to implement the `is` operator:

* Java has the `==` operator;
* .Net, or at least C#, has Object.ReferenceEquals

In particular, Jython and IronPython have to implement Python's 'id' and 'is'. I believe 'id' is a bit of a nuisance. One way is a permanent index into a list of mutable addresses. Once 'id' is done, 'is' should be easy.

Human interpreters of Python code normally skip 'id', but if knowledgable, somehow workout 'is' when it matters, for mutables, without 'id'. I am not quite sure yet how I do that. For builtin numbers and strings, we can identify 'is' and '==' unless trying to simulate the possibly version-specific CPython implementation.

--
Terry Jan Reedy
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/BOHRUX7BES4BHCU27NGBC2XMTYUITHAX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to