[issue36156] different method, but id function return same value.

Steven D'Aprano report at bugs.python.org
Fri Mar 1 08:30:00 EST 2019


Steven D'Aprano <steve+python at pearwood.info> added the comment:

bugs.python.org seems to be down at the moment, so please forgive me if 
this ticket has already been closed and I'm repeating what has already 
been said.

> This is guaranteed to be unique among simultaneously existing objects.

Note the *simultaneously existing* comment. Since the method objects a.a 
and a.a1 don't exist simultaneously, the interpreter is allowed to reuse 
the same ID for each.

(P.S. please, next time use less confusing names!)

Your code does this:

- fetch a.a, which returns a new method object;
- print the ID of that method object;
- throw away and garbage collect the method object;
- fetch a.a1, which returns a new method object;
- print the ID of that method object which happens
  to get the same value as the previous object;
- throw away and garbage collect the method object.

You can see the difference if you do this:

spam = a.a
eggs = a.a1
print(id(spam), id(eggs))

and you will get two different IDs.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36156>
_______________________________________


More information about the Python-bugs-list mailing list