Christian Heimes <li...@cheimes.de> added the comment:

This is not a bug. The "is" operator works as expected. A method descriptor 
returns a new wrapper object on each access.

CPython uses free lists to "recycle" memory locations to increase performance. 
id(Class.method.__get__(None, Class)) == id(Class.method) is true because the 
return value of "Class.method.__get__(None, Class)" is garbage collected and 
the memory address is reused.

See:

>>> class Class:
...     def method(self): ...
... 
>>> instance = Class()
>>> m1 = Class.method.__get__(instance, Class)
>>> m2 = instance.method
>>> id(m1) == id(m2)
False

----------
nosy: +christian.heimes
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39997>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to