[Python-ideas] unify usage of mutable and immutable objects

Terry Reedy tjreedy at udel.edu
Tue Feb 28 16:49:38 EST 2017


On 2/28/2017 1:48 PM, David Mertz wrote:
> So it sounds like what you want is this:
>
>     In [30]: class FrozenSet(frozenset):
>         ...:     def pop(self):
>         ...:         item = next(iter(self))
>         ...:         return item, self-{item}
>         ...:
>
>     In [31]: a = FrozenSet({1,2,3,4,5})
>
>     In [32]: a.pop()
>     Out[32]: (1, frozenset({2, 3, 4, 5}))
>
>
> I think I'm +1 on `frozenset` itself growing that method.

To me, 'pop' implies mutation.  Tuples do not have a pop method, and it 
is not obvious to me that either tuples or frozensets should.  What are 
the use cases that are not better served by converting to list or set?

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list