Making immutable instances

Mike Meyer mwm at mired.org
Fri Dec 2 01:18:42 EST 2005


Ben Finney <bignose+hates-spam at benfinney.id.au> writes:
> 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.

It doesn't say anything about that in the package, and there are no
docs in what's I downloaded from PyPI.

Doesn't live up to those promises, either.

But what's the point of promising that there won't be any attributes
that aren't values? Do you expect the user to know how to distinguish
implementation details from actual attributes(*), and get a list of
value names by filtering them from the attribute list? Wouldn't it be
easier to provide a method that returned a tuple of names - at least
easier than tuple(value.key for value in myenum)?

Sorry if you discussed this in the thread on the enum class, but I
didn't follow it.

        <mike

*) Actually, the user is required to know implementation details, as
otherwise they'll have problems with value names that collide with
them.
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list