Author antlong
Recipients antlong
Date 2011-04-14.21:12:46
SpamBayes Score 5.77316e-15
Marked as misclassified No
Message-id <1302815567.28.0.789640613127.issue11846@psf.upfronthosting.co.za>
In-reply-to
Content
http://docs.python.org/c-api/int.html

"The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of 1. I suspect the behaviour of Python in this case is undefined. :-)"

This paragraph should be changed to reflect that you can (by construction) mutate anything you want in C, and (as per suggestion of dmalcolm)

"The current implementatin consolidates integers in the range -5 to 256 (inclusive) into singleton instances.  Do not manipulate the internal value of a PyIntObject after creation."

Also, the last line of that paragraph insinuates this functionality (caching of -5 to 256) is undocumented. I searched for a good while for an answer for this, and I didn't find one. If there is something written on the implementation details surrounding why '-5 is -5' works, while -6 is -6' wouldn't. 

If there is nothing written about this, I will put something together. My final question however which I have not been able to find an answer for, is: Is this even necessary functionality?

I encountered around 100 blog posts and a couple of stackoverflow questions about why this fails, and it seems like 1) a source of confusion 2) a point of ridicule. Is it really necessary?

>>> id(1)
4298196440
>>> a = 1
>>> id(a)
4298196440
>>> id(3000)
4320396376
>>> a = 3000
>>> id(a)
4320396160
>>>
History
Date User Action Args
2011-04-14 21:12:47antlongsetrecipients: + antlong
2011-04-14 21:12:47antlongsetmessageid: <1302815567.28.0.789640613127.issue11846@psf.upfronthosting.co.za>
2011-04-14 21:12:46antlonglinkissue11846 messages
2011-04-14 21:12:46antlongcreate