Immutable instances, constant values

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Nov 17 22:32:46 EST 2005


Howdy all,

I've recently packaged 'enum' in PyPI. In its description, I make the
claim that it creates "immutable" enumeration objects, and that the
enumeration values are "constant" values.

This raises questions.

Is there any difference between a Python immutable value, and a
constant? I suppose "constant" also implies that the *name* binds
unchangeably to a particular value. Is that meaningful?

How does one actually ensure an object is immutable? Is it a matter of
overriding a bunch of methods, or is ther a neater way?

Is it bad style to make a user-defined class that creates immutable
objects? Why?

In the case of 'enum', can anyone argue for or against an enumerated
type being immutable? Its values being constant?

-- 
 \                "The best ad-libs are rehearsed."  -- Graham Kennedy |
  `\                                                                   |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list