Enumeration idioms: Values from different enumerations

Ben Sizer kylotan at gmail.com
Mon Dec 19 08:30:11 EST 2005


Steven D'Aprano wrote:
> On Fri, 16 Dec 2005 02:43:35 -0800, Ben Sizer wrote:
> > Is it possible to make it have the following sort of behaviour? :
> >
> >>>> ShirtSize.small == AppleSize.small
> > True
>
> Okay, so I was wrong to say that nobody was seriously suggesting that sort
> of behaviour.

I was working under what looks to have been an incorrect assumption
that someone was looking for a way to do the above. After all, it was
mentioned in what seemed like seriousness. I can't think of a use case
for it, myself.

> > It works for comparing a boolean (True) vs. an integer (1), so it has
> > some sort of precedent. (Especially if you make the tenuous assumption
> > that True,False are language-supported 'enums' for 0 and 1.)
>
> Enums are not conceptually subclasses of integers. Integers just happen to
> be a useful method to implement enumerations.

Aren't they? They have discrete values, can be ordered and compared for
equality, etc. I think the 'numerate' part of 'enumeration' is a hint
here. They certainly don't look much further from being integers than
booleans do. But, if nobody actually needs the behaviour I described
before, this point is irrelevant.

-- 
Ben Sizer




More information about the Python-list mailing list