[Python-bugs-list] [ python-Bugs-693121 ] Set == non-Set is a TypeError

SourceForge.net noreply@sourceforge.net
Fri, 28 Feb 2003 18:09:13 -0800


Bugs item #693121, was opened at 2003-02-25 14:37
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=693121&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Chris Reedy (creedy)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: Set == non-Set is a TypeError

Initial Comment:
Comparing Sets to non-Sets results in a TypeError. For
example:

>>> from sets import Set
>>> x = Set([1])
>>> x == 2
TypeError: Binary operation only permitted between sets

This seems to be inconsistent  with other Python
behavior. For example:

>>> (1,2,3) == 2
0
>>> "abcd" == 2
0

Assuming that the standard behavior is what is desired,
the implementation of __eq__ and other comparison
operators in sets.py should be changed to return
NotImplemented when the other object is not a Set.

Note: Looking at the code, I'm not sure whether the
implementation of __lt__, __le__, etc. should also be
changed to not return a Type Error.


----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-02-28 21:08

Message:
Logged In: YES 
user_id=80475

The OP added this note at the behest of 
comp.lang.python.  The thread is at:
http://tinyurl.com/6n91 and includes
some comments by Tim.

Assigning to Guido to decide whether he wants to keep 
that behavior.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=693121&group_id=5470