__eq__ and sets

Chris Reedy creedy at mitretek.org
Tue Feb 25 11:25:04 EST 2003


I recently encountered the following:

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

The TypeError is raised by Set.__eq__ (actually BaseSet.__eq__) upon 
recognizing that 2 is not a set.

My question: Is this the expected and/or appropriate behavior?

In the case in question, I was expecting false to be returned. Changing 
the __eq__ and __ne__ operators in sets.py to return NotImplemented 
instead or raising an exception would result in the behavior I was 
expecting.

   Chris

-- 
This is informal and not an official Mitretek Systems position.
Dr. Christopher L. Reedy, Senior Principal Software Engineer
Mitretek Systems, 3150 Fairview Park Drive South, Falls Church, VA 
22042-4519
Email: creedy at mitretek.org  Phone: (703) 610-1615  FAX: (703) 610-2203



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----




More information about the Python-list mailing list