Re: Enumeration idioms: Values from different enumerations

2005-12-23 Thread Steven D'Aprano
On Fri, 23 Dec 2005 23:51:22 +0200, Max wrote: > Steven D'Aprano wrote: >> >>>They certainly don't look much further from being integers than >>>booleans do. >> >> >> You think? >> >> hamburger, steak, fish, chicken, pizza >> >> What meaning do you give to steak**fish? Should that meaning ch

Re: Enumeration idioms: Values from different enumerations

2005-12-23 Thread Max
Steven D'Aprano wrote: > >>They certainly don't look much further from being integers than >>booleans do. > > > You think? > > hamburger, steak, fish, chicken, pizza > > What meaning do you give to steak**fish? Should that meaning change if I > happened to have written pizza first instead of

Re: Enumeration idioms: Values from different enumerations

2005-12-20 Thread Bengt Richter
On Tue, 20 Dec 2005 09:16:03 +1100, Ben Finney <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] writes: >> Ben Finney wrote: >>> Is there some behaviour other than "evaluate to False" or "raise an >>> exception", that could indicate "not comparable"? >> >> Yes: return NotImplemented. Note that the =

Re: Enumeration idioms: Values from different enumerations

2005-12-19 Thread Ben Finney
[EMAIL PROTECTED] writes: > Ben Finney wrote: >> Is there some behaviour other than "evaluate to False" or "raise an >> exception", that could indicate "not comparable"? > > Yes: return NotImplemented. Note that the == operator automagically > returns False in this case. > > >>> "spam".__eq__(

Re: Enumeration idioms: Values from different enumerations

2005-12-19 Thread eswald
Ben Finney wrote: > Antoon Pardon wrote: > > I just downloaded your enum module for python [from the Cheeseshop] > > and played a bit with it. IMO some of the behaviour makes it less > > usefull. > [...] > > I also think it would be more usefull if enums from different > > enumerations just tested

Re: Enumeration idioms: Values from different enumerations

2005-12-19 Thread Steven D'Aprano
On Mon, 19 Dec 2005 05:30:11 -0800, Ben Sizer wrote: >> 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. Just like: mammal, re

Re: Enumeration idioms: Values from different enumerations

2005-12-19 Thread Ben Sizer
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.

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Ben Finney
"Ben Sizer" <[EMAIL PROTECTED]> writes: > Transitivity within any single enumeration plus transivity of > equivalence across multiple enumerations, should be enough for most > needs, no? +1 to transitivity within an enumeration. -1 to transitivity across enumerations. If they're supposed to be equ

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Ben Finney
Paul Rubin writes: > All in all, comparing by object identity doesn't sound too good. > Maybe you want to have the enum contain its own name internally, and > do a string comparison. The "__eq__ compares identity" was a glib pseudo-implementation; I didn't think it throu

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Steven D'Aprano
On Fri, 16 Dec 2005 02:43:35 -0800, Ben Sizer wrote: > Ben Finney wrote: >> The problem with "is the same value" as an explanation for '==' is >> that it doesn't help in cases such as:: >> >> >>> ShirtSize = Enum('small', 'medium', 'large') >> >>> AppleSize = Enum('small', 'large') >> >> W

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Steven D'Aprano
On Fri, 16 Dec 2005 19:45:51 +1100, Ben Finney wrote: > The problem with "is the same value" as an explanation for '==' is > that it doesn't help in cases such as:: > > >>> ShirtSize = Enum('small', 'medium', 'large') > >>> AppleSize = Enum('small', 'large') > > What should be the result

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Steven D'Aprano
On Thu, 15 Dec 2005 23:53:36 -0500, Peter Hansen wrote: > Ben Finney wrote: >> These are valid concerns. I can't see how to reconcile these against >> the desire for values from different enums to fail comparison. >> >> Am I alone in my tri-state view of enumeration value comparisons? Can >> anyo

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Steven D'Aprano
On Fri, 16 Dec 2005 15:16:08 +1100, Ben Finney wrote: >> As can be seen from the above, you raise an exception when one wants >> to compare Enums from different enumarations, but it seems a bit >> strange that different enumerations belong to the same type. > > This does seem a point that could b

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Mike Meyer
Ben Finney <[EMAIL PROTECTED]> writes: > Mike Meyer <[EMAIL PROTECTED]> writes: >> Peter Hansen <[EMAIL PROTECTED]> writes: >>> That is, [perhaps] trying to compare enumerations that should not >>> be compared *is* an error (raising an exception) *because* the >>> whole point of enumerations is to

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread skip
ShirtSize = Enum('small', 'medium', 'large') AppleSize = Enum('small', 'large') Ben> What should be the result of this comparison:: ShirtSize.small == AppleSize.small False. They are values from different objects. Just make __eq__ map to "is". I think you'll be

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread skip
Without downloading and installing your code, can you tell me what the result of these comparisons would be? col = Enum('red', 'green', 'blue') day = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun') col.blue == "blue" day.tue == 23 If they return False I would expect co

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Ben Sizer
Antoon Pardon wrote: > Op 2005-12-16, Ben Sizer schreef <[EMAIL PROTECTED]>: > > Is it possible to make it have the following sort of behaviour? : > > > ShirtSize.small == AppleSize.small > > True > ShirtSize.small is AppleSize.small > > False > > > > It works for comparing a boolean (Tr

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Antoon Pardon
> Antoon Pardon wrote: >> Ben Finney wrote: >> > Would it be better if every Enum instance had its own unique >> > subclass of EnumValue, that was used to instantiate values for >> > that enumeration? >> >> If you decide on keeping the current behaviour when comparing >> values of different enumera

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes: > This gives meaning to the "equal value" comparisons, but ensures that > other comparisons are errors. > > Comments so far? What does copy.copy of an enumeration value do? What happens if you have a list with some enumeration values inside, and you make a

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Ben Finney
Antoon Pardon <[EMAIL PROTECTED]> writes: > Ben Finney wrote: >> The 'enum' package in Cheeseshop [defines enumerations as] >> sequences (of unique arbitrary values), that can be iterated and >> tested for membership. > > Sure but we do have this: > from enum import Enum day = Enum('mon',

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Antoon Pardon
Op 2005-12-16, Ben Sizer schreef <[EMAIL PROTECTED]>: > Ben Finney wrote: >> The problem with "is the same value" as an explanation for '==' is >> that it doesn't help in cases such as:: >> >> >>> ShirtSize = Enum('small', 'medium', 'large') >> >>> AppleSize = Enum('small', 'large') >> >> W

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Ben Sizer
Ben Finney wrote: > The problem with "is the same value" as an explanation for '==' is > that it doesn't help in cases such as:: > > >>> ShirtSize = Enum('small', 'medium', 'large') > >>> AppleSize = Enum('small', 'large') > > What should be the result of this comparison:: > > >>> Shirt

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Antoon Pardon
Op 2005-12-16, Ben Finney schreef <[EMAIL PROTECTED]>: > Mike Meyer <[EMAIL PROTECTED]> writes: >> Peter Hansen <[EMAIL PROTECTED]> writes: >>> That is, [perhaps] trying to compare enumerations that should not >>> be compared *is* an error (raising an exception) *because* the >>> whole point of enu

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Ben Finney
Mike Meyer <[EMAIL PROTECTED]> writes: > Peter Hansen <[EMAIL PROTECTED]> writes: >> That is, [perhaps] trying to compare enumerations that should not >> be compared *is* an error (raising an exception) *because* the >> whole point of enumerations is to avoid errors in such cases. > > Except it mig

Re: Enumeration idioms: Values from different enumerations

2005-12-16 Thread Antoon Pardon
Op 2005-12-16, Ben Finney schreef <[EMAIL PROTECTED]>: > [quoting private email with permission] > > Antoon Pardon wrote: >> I just downloaded your enum module for python [from the Cheeseshop] >> and played a bit with it. IMO some of the behaviour makes it less >> usefull. > > Feedback is appreciat

Re: Enumeration idioms: Values from different enumerations

2005-12-15 Thread Mike Meyer
Peter Hansen <[EMAIL PROTECTED]> writes: > For example, if enumerations are intended to reduce the likelihood of > certain types of errors (where the use of typical =3 "constants" > might be more prone to errors), then perhaps this suggests that > passing errors silently is bad. That is, tryin

Re: Enumeration idioms: Values from different enumerations

2005-12-15 Thread Peter Hansen
Ben Finney wrote: > These are valid concerns. I can't see how to reconcile these against > the desire for values from different enums to fail comparison. > > Am I alone in my tri-state view of enumeration value comparisons? Can > anyone else defend why values from different enumerations should not