ANN: set-0.2 module available

Aric Coady coady at bent-arrow.com
Tue May 21 22:05:56 EDT 2002


On Tuesday, May 21, 2002, at 03:15 AM, Denis S. Otkidach wrote:
> Here is another problem:
>>>> from set import set
>>>> s=set((1,3,5))
>>>> hash(s)
> 1272199707
>>>> s&=set((2,4,6))
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: set has become immutable
>
> If the set became immutable it should not be modified in-place,
> but &= operator should create new object according to ?=
> documentation.  Unfortunately, it makes this error prone "2 in 1"
> solution even more hard to debug.

I agree that's unfortunate, but I like the alternative even less.  To 
me, the fact that it will raise an error if you inadvertently use a set 
as if it's both mutable and hashable is precisely the reason why it's an 
acceptable compromise to let it act as either mutable or hashable.

If I had to give up those immutable errors, I'd rather just choose one 
(mutable) to be the default and force those who want it to be hashable 
to choose that explicitly.






More information about the Python-list mailing list