Making immutable instances

Paul Rubin http
Wed Nov 30 00:43:06 EST 2005


Mike Meyer <mwm at mired.org> writes:
> 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. If you've got a
> use case, I'd be interested in hearing it.

I see it the other way; almost all the time in my own code I try to
initialize all of any instance's attributes in an __init__ method.
Dynamically adding attributes is useful sometimes, but done
willy-nilly leads to spaghetti code.  In the cases where it's useful,
I'd rather see it done through a special __setattr__ method, perhaps
inherited from a mixin:

  class Frob(Whatsit, DynamicAttributeMixin):
     ...

However, that's not likely to happen.



More information about the Python-list mailing list