Making immutable instances

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Dec 1 23:51:17 EST 2005


Mike Meyer <mwm at mired.org> wrote:
> Ben Finney <bignose+hates-spam at benfinney.id.au> writes:
> >     "Since the values of an enumeration are directly reflected in
> >     the values and attributes, Enum instances are immutable to
> >     preserve this relationship"
> 
> This justifies making the attributes immutable. But that's old hat -
> I had that use case last year. It doesn't justify making the
> instances immutable. Or if it does, I missed it.

The Enum class promises that instances will have all the enumeration
values as instance attributes, and that all the instance attributes
are values in the enumeration. That requires that the set of
attributes on the instance not be changed after creation.

-- 
 \      "The future always arrives too fast, and in the wrong order."  |
  `\                                                  -- Alvin Toffler |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list