Making immutable instances

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Nov 26 03:39:20 EST 2005


On Fri, 25 Nov 2005 23:20:05 -0500, Mike Meyer wrote:

> Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
>> "Hmmm, the class designer didn't want me adding attributes to instances...
>> maybe he had a good reason for that..."
> 
> When it was suggested that a facility for doing this be added to the
> language, I asked for a use case for it. Nobodies come up with a
> reason for placing such restriction on the client yet.

Oh, I think it is terribly unfair to call them nobodies, even if you don't
like their use-cases *grin*

> If you've got a use case, I'd be interested in hearing it.

frozenset perhaps? If it were needed once, it could be needed again.

The obvious case would be for a class where distinct instances that
compare equal but not identical map to the same value in a dict.

In any case, I'm not the one claiming that I need custom immutable
classes. I'm just suggesting that there is nothing non-Pythonic about
them. If Ben thinks he needs them, I'm sure he has put *far* more thought
into it than I have. I know Ben in RL, and he is not someone to make snap
judgements about turning Python into Some Other Language Just Because.


-- 
Steven.




More information about the Python-list mailing list