[IronPython] Is this a bug in IP 2.0?

Curt Hagenlocher curt at hagenlocher.org
Wed Dec 24 19:29:13 CET 2008

On Wed, Dec 24, 2008 at 10:05 AM, Tim Roberts <timr at probo.com> wrote:

> But, this has to be considered a rather serious bug, doesn't it?  If I
> create an object p2, then insert it into a list at l[0], the Python contract
> guarantees that l[0] and p2 are references to the same object, so that
> modifying one must modify the other.

CLR value types simply don't map well onto Python objects, because CPython
doesn't have any value types.  All objects are basically references.  In the
CLR, we convert value types into reference types by "boxing" them, and it's
only in this state that they have an "identity".  When a value type is
unboxed and reboxed, it acquires a whole new identity, and therefore a new
"id".  If you're familiar with the CPython "C" language API, you can think
of this as the distinction between the numeric value stored inside an "int"
PyObject, and the PyObject itself.

I believe that the current "best practices" for CLR value types are to
encourage people to treat them as immutable.  If you do this, the lack of
reference equality is no longer quite as important :).

I don't know whether or not the specific behavior you've identified is a
bug, but you should definitely enter it into CodePlex so that it can be
tracked and investigated properly.

Curt Hagenlocher
curt at hagenlocher.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081224/c81fe617/attachment.html>

More information about the Ironpython-users mailing list