set of sets

Paolo Veronelli paolo_veronelli at yahoo.it
Thu Aug 11 11:09:55 EDT 2005


Paolino wrote:
> I thought rewriting __hash__ should be enough to avoid mutables problem but:
> 
> class H(set):
>    def __hash__(self)
>      return id(self)
> 
> s=H()
> 
> f=set()
> 
> f.add(s)
> f.remove(s)
> 
> the add succeeds
> the remove fails eventually not calling hash(s).
> 

Yes this is really strange.

from sets import Set
class H(Set):
   def __hash__(self):
     return id(self)

s=H()
f=set() #or f=Set()

f.add(s)
f.remove(s)

No errors.

So we had a working implementation of sets in the library an put a 
broken one in the __builtins__ :(

Should I consider it a bug ?

Regards Paolino

		
___________________________________ 
Aggiungi la toolbar di Yahoo! Search sul tuo Browser, e'gratis! 
http://it.toolbar.yahoo.com



More information about the Python-list mailing list