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.

classification
Title: `is' operator returns False on classmethods
Type: behavior Stage: resolved
Components: Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: mstefanro, ncoghlan
Priority: normal Keywords:

Created on 2012-08-23 23:35 by mstefanro, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
is_on_classmethods.py mstefanro, 2012-08-23 23:35
Messages (2)
msg168967 - (view) Author: Stefan Mihaila (mstefanro) * Date: 2012-08-23 23:35
Here are a few counter-intuitive outputs:

    >>> dict.fromkeys is dict.fromkeys
    False

    >>> id(dict.fromkeys) == id(dict.fromkeys)
    True

    >>> x=dict.fromkeys; id(x) == id(x)
    True

    >>> x=dict.fromkeys; id(x) == id(dict.fromkeys)
    False
    
    >>> x=dict.fromkeys; y=dict.fromkeys; id(x),id(y),id(dict.fromkeys)
    (39888824, 39064632, 39065144)

    >>> a=id(dict.fromkeys); x=dict.fromkeys; b=id(dict.fromkeys); a,b
    (39888824, 39480568)

Attached is a failing test.
msg168968 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-08-24 00:50
Bound methods are created dynamically on lookup, while object ids may be reused after the original object is destroyed.

There's no bug here - just a combination of those two language behaviours that is frequently surprising to users that have just noticed it.

There's not a lot we can do about that - it's a genuinely surprising moment in people's understanding of the way methods (and descriptors in general) work.
History
Date User Action Args
2022-04-11 14:57:35adminsetgithub: 59977
2012-08-24 00:50:13ncoghlansetstatus: open -> closed

nosy: + ncoghlan
messages: + msg168968

resolution: not a bug
stage: resolved
2012-08-24 00:02:31mstefanrosettype: behavior
2012-08-23 23:35:07mstefanrocreate