This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author antlong
Recipients antlong
Date 2011-04-14.21:12:46
SpamBayes Score 5.77316e-15
Marked as misclassified No
Message-id <>

"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)
>>> a = 1
>>> id(a)
>>> id(3000)
>>> a = 3000
>>> id(a)
Date User Action Args
2011-04-14 21:12:47antlongsetrecipients: + antlong
2011-04-14 21:12:47antlongsetmessageid: <>
2011-04-14 21:12:46antlonglinkissue11846 messages
2011-04-14 21:12:46antlongcreate