Making immutable instances

Steven D'Aprano steve at
Sat Nov 26 02:08:15 CET 2005

On Thu, 24 Nov 2005 11:44:16 -0500, Mike Meyer wrote:

> In Python, I can even fix
> it so *your* code uses my wrapped version:
> import Finney
> class Addable(Finnney.Immutable): pass
> Finney.Immutable = Addable
> Which means that from now on *your* code that tries to create
> Immutables will actually get Addables. The inability to do this in B&D
> languages is - well, painfull. That Python doesns't require the
> boilerplate in a good thing.

The ability to shoot yourself in the foot *if you want to* is a feature,
not a bug. But the ability to shoot yourself in the foot *accidentally* is
not a feature.

I am happy that whatever restrictions the class designer builds on their
class is easy to bypass, because the class designer is not omniscient
and their "private data" may be just the thing I need to solve a
problem some day. But I should have to *think about it* before messing
about with it.

Python's consenting adults philosophy allows the class designer some
limited ability to force the class user to think about it before messing
about with private variables. I think Ben's immutable class falls into
that same category.


More information about the Python-list mailing list