Making immutable instances

bonono at gmail.com bonono at gmail.com
Wed Nov 30 01:51:07 EST 2005


Mike Meyer wrote:
> The thing is, the need for an extra attribute doesn't come from your
> class, it comes from the client of your class. You can't know if the
> client code will need that facility or not, so the only choice you
> know won't be wrong sometime is to always add the mixin. In which
> case, you should follow the Python "the less boilerplate, the better"
> practice, and leave it off. Which is what we have.
>
> Letting the class author declare whether or not the client can add
> attributes is wrong for the same reasons - and in the same places -
> that letting the class author declare that the client shouldn't be
> allowed to access specific attributes, and so on, is wrong.  Of
> course, it's also *right* for the same reasons and in the same places
> as those things. I just don't think those places happen in Python
> programs.
>
I am puzzled, and could have read what you want wrong. Are you saying
you want something like this :

a={}
a.something = "I want to hang my stuff here, outside the intended use
of dict"




More information about the Python-list mailing list