I understand that the built-in python id() returns an identifier unique to the life of the object. I understand that objects with non-overlapping lifetimes can have the same identifier. However, I am trying to understand this rather confusing behavior:
>>> id(matplotlib.image.BboxImage.set_cmap) 4424372944 >>> id(numpy.ma.core.MaskedArray.sum) 4424372944
And in fact, in multiple instances of the interpreter, the behavior is repeatable:
Mac:~$ python2.7 -c "import matplotlib.image; import numpy; print id(matplotlib.image.BboxImage.set_cmap), id(numpy.ma.core.MaskedArray.sum)" 4343186208 4343186208 Mac:~$ python2.7 -c "import matplotlib.image; import numpy; print id(matplotlib.image.BboxImage.set_cmap), id(numpy.ma.core.MaskedArray.sum)" 4521153312 4521153312 Mac:~$ python2.7 -c "import matplotlib.image; import numpy; print id(matplotlib.image.BboxImage.set_cmap), id(numpy.ma.core.MaskedArray.sum)" 4358591264 4358591264 Mac:~$ python2.7 -c "import matplotlib.image; import numpy; print id(matplotlib.image.BboxImage.set_cmap), id(numpy.ma.core.MaskedArray.sum)" 4389970720 4389970720
It seems that matplotlib.image.BboxImage.set_cmap and numpy.ma.core.MaskedArray.sum always get the same identifier from each other, even with different installations of the python interpreter.
Now I understand that this is consistent with the docs for id() , as these two objects are created dynamically upon access and, therefore, will have non-overlapping lives. But why do these two unrelated objects always end with the same identifier?
(This question is different from Object methods of the same class have the same identifier? Because here I ask why this is repeated in multiple instances of the interpreter, and not just a false id collision with objects with non-overlapping lifetimes.)
source share