id(a) == id(b) and a is not b --> bug?

Gerrit Holl gerrit at nl.linux.org
Thu Jun 5 21:49:59 CEST 2003


Hi,

according to the reference manual:

The `is' operator compares the identity of two objects; the id() function returns an integer representing its identity

This would mean that "id(a) == id(b)" is the same as "a is b".
However:

#!/usr/bin/env python

class autosuper(type):
    def __init__(cls, name, bases, dict):
        s = super(cls)
        setattr(cls, "super", s)
        setattr(cls, "super2", s)

class A:
    __metaclass__ = autosuper
    def meth(self):
        print "id's equal =>", id(self.super) == id(self.super2)
        print "same object =>",  self.super is self.super2

A().meth()

Results in:

$ python meta.py
id's equal => True
same object => False

Is this a bug? It is true both for Python 2.3b1+ and Python 2.2.

yours,
Gerrit.

-- 
168. If a man wish to put his son out of his house, and declare before
the judge: "I want to put my son out," then the judge shall examine into
his reasons. If the son be guilty of no great fault, for which he can be
rightfully put out, the father shall not put him out.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list