Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
ID numbers in Python are only guaranteed to be unique for the lifespan of the object. In CPython they can be re-used. (In other implementations, like Jython and IronPython, IDs are allocated as sequential numbers and won't be reused.) The other fact you may be missing is that method objects are generated on the fly each time you look them up. So: py> class X: ... def method(self): pass ... py> x = X() py> a = x.method py> b = x.method py> a is b False So your example is now understandable: you generate a method object, get its ID, and then the method object is garbage collected, allowing the ID to be reused. Which *in this case* it is. Whether it is or isn't re-used is an accident of implementation. In other words: nothing to see here. Its not a bug, just the normal behaviour of IDs and garbage collection. ---------- nosy: +steven.daprano resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33685> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com