Python interpreter bug

Steve Holden steve at holdenweb.com
Fri Oct 7 12:00:59 EDT 2005


alainpoint at yahoo.fr wrote:
> I understand this, Steve.
> I thought the _cmp_ method was a helper for sorting purposes. Why is it
> that a membership test needs to call the __cmp__ method?

Can you suggest another way to test for set membership, given that 
instances aren't singletons? The only way to do so is to iterate over 
the list, asking "are these the same instance", followed (in the case of 
a "no" answer) by "are these two instances equal?".

Consider:

 >>> a = {1:'one'}
 >>> b = {2:'two'}
 >>> c = {1:'one'}
 >>> a is c
False
 >>> a in [b, c]
True
 >>>

What would you have Python do differently in these circumstances?

> If this isn't a bug, it is at least unexpected in my eyes.

Ah, right. So it's your eyes that need fixing! :-)

> Maybe a candidate for inclusion in the FAQ?
> Thank you for answering

A pleasure.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list