Re: PEP 354: Enumerations in Python

2006-03-03 Thread Christos Georgiou
On 26 Feb 2006 22:30:28 -0800, rumours say that "Crutcher" <[EMAIL PROTECTED]> might have written: >This seems great, except why can't I compare strings? It seems too >useful when dealing with user input, or parsing messages or config >files. > Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes: > > I don't know about this. It makes athlon64_instructions a > > completely separate enum from pentium_instructions. It could be > > that athlon64_instructions.add should be the same as > > pentium_instructions.add . > > If you want the members of two dist

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Ben Finney
Paul Rubin writes: > I don't know about this. It makes athlon64_instructions a > completely separate enum from pentium_instructions. It could be > that athlon64_instructions.add should be the same as > pentium_instructions.add . If you want the members of two distinct

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Roy Smith
>> Should I amend the PEP to propose "either in the builtins >> or in the collections module"? Or should I propose two >> PEPs and let them compete? I see the issue of whether it's a built-in or part of the standard library as being a detail. My personal opinion is that they're important enough

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Terry Hancock
On Wed, 01 Mar 2006 12:37:26 +1100 Ben Finney <[EMAIL PROTECTED]> wrote: > Ben Finney <[EMAIL PROTECTED]> writes: > > PEP:354 > > Title: Enumerations in Python > > Version:$Revision: 42186 $ > > Last-Modified: $Date: 2006-01-26 11:55:20 +1100 (Thu, > > 26 Jan 2006) $ >

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Terry Hancock
On Wed, 01 Mar 2006 12:26:19 +1100 Ben Finney <[EMAIL PROTECTED]> wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > > -1 on the proposal as-is. I don't have many use cases > > for enumerations, and I don't think they merit appearing > > in the builtins. If you put them in the collections > > m

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Peter Maas
Paul Rubin schrieb: >> But if you have a good usage case for an empty enum, please feel free >> to tell us. > > Do you have a good usage case for the number > 647574296340241173406516439806634217274336603815968998799147348150763731 ? Yes, it could be the value of my property in any currency :) Bu

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Raymond Hettinger
[Ben Finney] > It is possible to simply define a sequence of values of some other > basic type, such as ``int`` or ``str``, to represent discrete > arbitrary values. However, an enumeration ensures that such values > are distinct from any others, and that operations without meaning > ("Wednesday t

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Roy Smith
Tim Chase <[EMAIL PROTECTED]> wrote: >>> Do you anticipate having parameters like socket.AF_INET >>> that are currently integers, become enumeration members >>> in future releases? >> >> Since these are derived from values defined as integers >> in C, it's probably better to leave them that way.

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Tim Chase
>> Do you anticipate having parameters like socket.AF_INET >> that are currently integers, become enumeration members >> in future releases? > > Since these are derived from values defined as integers > in C, it's probably better to leave them that way. There > may be code that relies on them bein

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Roy Smith
In article <[EMAIL PROTECTED]>, greg <[EMAIL PROTECTED]> wrote: > Paul Rubin wrote: > > > Do you anticipate having parameters like socket.AF_INET that are > > currently integers, become enumeration members in future releases? > > Since these are derived from values defined > as integers in C, i

Re: PEP 354: Enumerations in Python

2006-03-01 Thread greg
Dan Sommers wrote: > In some parts of the world, calendar weeks begin on Monday > and end on Sunday, and in other parts of the world, work weeks begin on > Sunday and end on Thursday. Things like days of the week really have a circular ordering, so it doesn't inherently make sense to ask whether

Re: PEP 354: Enumerations in Python

2006-03-01 Thread greg
Giovanni Bajo wrote: > What's the repr of an enumeration value? OTOH, it should be something like > "Weekdays.wed", so that eval(repr()) holds true. Also, it'd be very useful in > debug dumps, tracebacks and whatnot. That would be nice, but I don't think that's possible with what the PEP proposes

Re: PEP 354: Enumerations in Python

2006-03-01 Thread greg
Paul Rubin wrote: > Do you anticipate having parameters like socket.AF_INET that are > currently integers, become enumeration members in future releases? Since these are derived from values defined as integers in C, it's probably better to leave them that way. There may be code that relies on the

Re: PEP 354: Enumerations in Python

2006-03-01 Thread greg
Ben Finney wrote: > On the assumption these might be basic types, though, that > name doesn't read so easily in lowercase ('enummember'). Maybe 'enumval'? I also thought of 'enumber' (from munging together 'enum' and 'member') but that looks too much like 'e-number' rather than 'enum-ber'. -- Gr

Re: PEP 354: Enumerations in Python

2006-03-01 Thread greg
Steven D'Aprano wrote: > You can't shell an egg that isn't there. Yesterday upon the stair I shelled an egg that wasn't there. I'd shell the thing again today If only I could find a way. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 354: Enumerations in Python

2006-03-01 Thread Steven Bethard
Ben Finney wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > >> Ben Finney wrote: >>> This PEP specifies an enumeration data type for Python. >>> An enumeration is an exclusive set of symbolic names bound to >>> arbitrary unique values. Values within an enumeration can be iterated >>> and com

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Terry Reedy
"Ben Finney" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Should I amend the PEP to propose "either in the builtins or in the > collections module"? Yes, if the idea is accepted, Guido and devs will debate and decide that anyway ;-) > Or should I propose two PEPs and let them

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Roy Smith
Ben Finney <[EMAIL PROTECTED]> wrote: > > a = enum ('foo', 'bar', 'baz') > > b = enum ('foo', 'bar', 'baz') > > Two separate enumerations are created OK, most of the rest follows from that. > > str (a) > > Not defined in the current specification. Suggestions? Well, by analogy with >>> a = s

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Felipe Almeida Lessa
Em Seg, 2006-02-27 às 17:10 -0800, Paul Rubin escreveu: > Ben Finney <[EMAIL PROTECTED]> writes: > > If an enumeration object were to be derived from, I would think it > > just as likely to want to have *fewer* values in the derived > > enumeration. Subclassing would not appear to offer a simple wa

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes: > These don't seem simple or elegant. I don't see a particular benefit > to doing it that way, rather than being explicit about manipulating > the member list:: > > pentium_instructions = enum('add', 'sub', 'mul') > athlon64_instructions = enum( >

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Ben Finney
Ben Finney <[EMAIL PROTECTED]> writes: > PEP:354 > Title: Enumerations in Python > Version:$Revision: 42186 $ > Last-Modified: $Date: 2006-01-26 11:55:20 +1100 (Thu, 26 Jan 2006) $ Most people seem to be unopposed or in favour of some kind of enumeration mechanism mak

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Ben Finney
Toby Dickenson <[EMAIL PROTECTED]> writes: > On Monday 27 February 2006 02:49, Ben Finney wrote: >> Coercing a value from an enumeration to a ``str`` results in the >> string that was specified for that value when constructing the >> enumeration:: > > That sentence seems to assume that all enumera

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Ben Finney
Steven Bethard <[EMAIL PROTECTED]> writes: > Ben Finney wrote: >> This PEP specifies an enumeration data type for Python. >> An enumeration is an exclusive set of symbolic names bound to >> arbitrary unique values. Values within an enumeration can be iterated >> and compared, but the values have

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Ben Finney
Roy Smith <[EMAIL PROTECTED]> writes: > A few random questions: > > a = enum ('foo', 'bar', 'baz') > b = enum ('foo', 'bar', 'baz') Two separate enumerations are created, and bound to the names 'a' and 'b'. Each one has three unique member values, distinct from any others. > what's the value of

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Ben Finney
Paul Rubin writes: > Do you anticipate having parameters like socket.AF_INET that are > currently integers, become enumeration members in future releases? That, and the 're' flags referred to earlier, seems to be a good application of enumerations. -- \ "Jealousy:

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Ben Finney
Paul Rubin writes: > say that >Weekdays = enum('mon', 'tue', ...) > > What is the type of Weekdays.mon supposed to be? The specification doesn't mention that; it should. I'm calling them EnumValue, but that makes it difficult to talk about. The term "value" is com

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Ben Finney
Paul Rubin writes: > Ben Finney <[EMAIL PROTECTED]> writes: >> If an enumeration object were to be derived from, I would think it >> just as likely to want to have *fewer* values in the derived >> enumeration. Subclassing would not appear to offer a simple way to >> do t

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Terry Hancock
On 28 Feb 2006 09:58:47 -0800 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Add me to the "me, too!" list of people who think > enumerations would be better off without > or < > comparison. +1 on "unordered" Comparable enums do have use-cases (like the days of the week), but I can't think of m

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Terry Hancock
On Tue, 28 Feb 2006 14:26:49 -0500 "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Stefan Rank" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > recent examples from this list: > > > > 2006-01-03: > > http://www.nabble.com/Re%3A-Regex-anomaly-p2179421.html > > 2006-02-20: > > http://w

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Terry Reedy
"Stefan Rank" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > recent examples from this list: > > 2006-01-03: http://www.nabble.com/Re%3A-Regex-anomaly-p2179421.html > 2006-02-20: > http://www.nabble.com/Re%3A-Regular-expression-gone-mad-p3029028.html If the re flags were implement

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Toby Dickenson
On Monday 27 February 2006 02:49, Ben Finney wrote: > Coercing a value from an enumeration to a ``str`` results in the > string that was specified for that value when constructing the > enumeration:: That sentence seems to assume that all enumeration values will have been specified as strings. T

Re: PEP 354: Enumerations in Python

2006-02-28 Thread [EMAIL PROTECTED]
Ben Finney wrote: > PEP 354: Enumerations in Python has been accepted as a draft PEP. The > current version can be viewed online: -1 on the proposal as a builtin, -0 on including any kind of enumeration in the standard library unless I can see a compelling use case; Carl Banks' app

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Steven Bethard
Ben Finney wrote: > This PEP specifies an enumeration data type for Python. > > An enumeration is an exclusive set of symbolic names bound to > arbitrary unique values. Values within an enumeration can be iterated > and compared, but the values have no inherent relationship to values > outside th

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Stefan Rank
on 28.02.2006 12:14 Carl Banks said the following: [snip] > >>> It's a pretty weak case to have a dedicated builtin to prevent >>> duplicates in something that changes maybe once a month, as enums tend >>> to change rather slowly. (At least, that's the way enums in other >>> languages are used, a

Re: PEP 354: Enumerations in Python

2006-02-28 Thread JW
It seems the concensus is that empty enums should be allowed for consistancy, and to support the loop that doesn't. I thought I'd find some data points in other languages as a guide: * C - builtin, empty enumerations not allowed * C++ - builtin, empty enumerations allowed. C++ doesn't have itera

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Cyril Bazin
What about that? SomeNumbers = enum('0', '1', '2', '3', '4', '5', '6', '7') or Rooms = enum('1bed', '2beds', 'moreThan2beds') or even Comments = enum('#', ';', '//') CyrilOn 28 Feb 2006 03:14:25 -0800, Carl Banks <[EMAIL PROTECTED]> wrote: Stefan Rank wrote:> on 28.02.2006 07:50 Carl Banks s

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Carl Banks
Stefan Rank wrote: > on 28.02.2006 07:50 Carl Banks said the following: > > Ben Finney wrote: > >> This PEP specifies an enumeration data type for Python. > > > [snip] > > > > Here's why I think it's not too useful to begin with: the benefits of > > the enum you describe here are pretty weak. > > I

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Stefan Rank
on 28.02.2006 07:50 Carl Banks said the following: > Ben Finney wrote: >> This PEP specifies an enumeration data type for Python. > [snip] > > Here's why I think it's not too useful to begin with: the benefits of > the enum you describe here are pretty weak. I need to disagree heavily here :) +

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Magnus Lycka
Tim Chase wrote: > ...throw UnthrowableKoan > ... > > (okay...maybe it's a little too early on a weekdays.mon morning) Probably, since a SyntaxError slipped in. Throw is C++ Tim. It's "raise UnRaisableKoan". -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Carl Banks
Ben Finney wrote: > This PEP specifies an enumeration data type for Python. -1 for this particular proposal as a builtin. I feel it's not a great design of something that isn't terribly useful to begin with. +0 for the standard library, only after a couple changes. As I see it, this whole propo

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Alex Martelli
Ben Finney <[EMAIL PROTECTED]> wrote: ... > The Python parser knows what to do when a comparison returns > NotImplemented. The parser has nothing to do with it, but the bytecode interpreter sure does;-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Alex Martelli
Terry Reedy <[EMAIL PROTECTED]> wrote: ... > I suspect that the notion of empty set was once controversial. Yep: Reverend Dodgson (best known by his pen name of Lewis Carroll, and as the author of the Alice novels, but a logician and mathematician IRL) fought long and hard against Cantor's set

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Roy Smith
A few random questions: a = enum ('foo', 'bar', 'baz') b = enum ('foo', 'bar', 'baz') what's the value of the following: a == b a is b a.foo == b.foo a.foo is b.foo len (a) str (a) repr (a) hash (a) type (a) Can you make an enum from a sequence? syllables = ['foo', 'bar', 'baz'] c = enum (syll

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Ben Finney <[EMAIL PROTECTED]> wrote: > I'll amend the specification so empty enumerations are not an > error. (This will also remove the last remaining exception class from > the specification, making it cleaner still. Good.) And once you've done that, we can bui

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes: > By way of explanation, my earlier implementations of this didn't have > enumerations as sequences. Now that the design has converged more on a > sequence and container idiom, I agree with you. say that Weekdays = enum('mon', 'tue', ...) What is the typ

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Ben Finney
Tim Chase <[EMAIL PROTECTED]> writes: > Just a couple thoughts: Appreciated. >> An enumeration is an exclusive set of symbolic names bound >> to arbitrary unique values. > > Uniqueness imposes an odd constraint that you can't have synonyms in > the set: > > >>> shades = enum({white:100, grey:50,

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Ben Finney
"Giovanni Bajo" <[EMAIL PROTECTED]> writes: > Ben Finney wrote: >> Values within an enumeration cannot be meaningfully compared except >> with values from the same enumeration. The comparison operation >> functions return ``NotImplemented`` [#CMP-NOTIMPLEMENTED]_ when a >> value from an enumeratio

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes: > If an enumeration object were to be derived from, I would think it > just as likely to want to have *fewer* values in the derived > enumeration. Subclassing would not appear to offer a simple way to do > that. pentium_instructions = enum('add', 'sub', 'mul'

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Mikalai
Steven D'Aprano wrote: > Paul Rubin wrote: > > What is an empty enum? How and when would you use it? > > The best I can come up with is that an empty enum would > be the enumerated values you have when you don't > actually have any enumerated values. This is not to be > confused with an empty list:

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Ben Finney
"Terry Reedy" <[EMAIL PROTECTED]> writes: > "Steven D'Aprano" <[EMAIL PROTECTED]> wrote >> A list is a container. > > I think it is misleading, if not wrong, to refer to Python > collections as 'containers', 'boxes', or similar. A object in a box > cannot be in another disjoint box. A object in a

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Ben Finney
Paul Rubin writes: > Hmm, I also see the PEP doesn't specify what's supposed to happen with > > Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') > Solar_system = enum('sun', 'mercury', 'venus', 'earth',) # etc. > print Weekdays.sun == Solar_system.s

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Ben Finney
Paul Rubin writes: > Ben Finney <[EMAIL PROTECTED]> writes: >> Enumerations with no values are meaningless. The exception >> ``EnumEmptyError`` is raised if the constructor is called with no >> value arguments. > > Why are empty enumerations not allowed? Empty sets, emp

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Ben Finney
"Giovanni Bajo" <[EMAIL PROTECTED]> writes: > Kay Schluehr wrote: >> Ben Finney wrote: >>> One motivation for having a class (rather than an instance) for >>> each enumeration is to allow subclasses of enumerations, extending >>> and altering an existing enumeration. A class, though, implies >>> t

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Paul Rubin
"I V" <[EMAIL PROTECTED]> writes: > I think it does, doesn't it? From the PEP: > > "Values within an enumeration cannot be meaningfully compared *except > with values from the same enumeration*. The comparison operation > functions return ``NotImplemented`` [#CMP-NOTIMPLEMENTED]_ when a > value f

Re: PEP 354: Enumerations in Python

2006-02-27 Thread I V
Paul Rubin wrote: > Hmm, I also see the PEP doesn't specify what's supposed to happen with > > Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') > Solar_system = enum('sun', 'mercury', 'venus', 'earth',) # etc. > print Weekdays.sun == Solar_system.sun > > so that's another sho

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Terry Reedy
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote > A list of X is like a box containing X, and in another post > A list is a container. I think it is misleading, if not wrong, to refer to Python collections as 'containers', 'boxes', or similar. A object in a box cannot be in another disjoint box

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Dan Sommers
On Mon, 27 Feb 2006 03:13:08 -0600, Tim Chase <[EMAIL PROTECTED]> wrote: > Same could go for days of the week: dow=enum(("sunday", 0), ("monday", 1), > ("start_of_work_week", 1), ... ("friday", 5), > ("end_of_work_week", 5)...) Not really: In some parts of the world, calendar weeks begin

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Eric Nieuwland
On 27 feb 2006, at 10:13, Tim Chase wrote: >> Uniqueness imposes an odd constraint that you can't have >> synonyms in the set: >> > shades = enum({white:100, grey:50, gray:50, black:0}) > > Blast, I hate responding to my own posts, but as soon as I > hit Send, I noticed the syntax here was bif

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > But if you have a good usage case for an empty enum, > please feel free to tell us. I could see empty enums being useful in machine-generated code, perhaps when generating wrappers around C library APIs. There might

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Tim Chase
> Uniqueness imposes an odd constraint that you can't have > synonyms in the set: > > >>> shades = enum({white:100, grey:50, gray:50, black:0}) Blast, I hate responding to my own posts, but as soon as I hit Send, I noticed the syntax here was biffed. Should have been something like >>> sha

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Tim Chase
Just a couple thoughts: > An enumeration is an exclusive set of symbolic names bound > to arbitrary unique values. Uniqueness imposes an odd constraint that you can't have synonyms in the set: >>> shades = enum({white:100, grey:50, gray:50, black:0}) Not a bad thing, as it would then have i

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Tim Chase
>>Why are empty enumerations not allowed? Empty sets, empty lists, >>empty dictionaries are all allowed. I don't see any obvious benefits >>to not allowing empty enumerations. > > What is an empty enum? How and when would you use it? It's a Zen thing :) (agh! not the zen thread!) >>> roundS

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Antoon Pardon
Op 2006-02-27, Steven D'Aprano schreef <[EMAIL PROTECTED]>: > Paul Rubin wrote: > >> Ben Finney <[EMAIL PROTECTED]> writes: >> >>>Enumerations with no values are meaningless. The exception >>>``EnumEmptyError`` is raised if the constructor is called with no >>>value arguments. >> >> >> Why are

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > All of the machinery of the enum class created by Ben Finney is just to > make sure that red, green and blue behave correctly, without extraneous > string-like or number-like methods. Of course Ben could modify his code so > that enum() returned an obje

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Paul Rubin
Felipe Almeida Lessa <[EMAIL PROTECTED]> writes: > > If enums aren't supposed to work in that construction then the PEP > > shouldn't specify that they work that way. > > Sorry, but where do they say that? The PEP gives an example of iterating through the members of an enum. I'm not sure if that

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Steven D'Aprano
On Mon, 27 Feb 2006 00:43:45 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> What is an empty enum? > > An empty enum is an enum with no identifiers, just like an empty list > is a list with no elements. No, I don't think that is the case. A list is a container. You ca

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Felipe Almeida Lessa
Em Seg, 2006-02-27 às 02:42 -0800, Paul Rubin escreveu: > Felipe Almeida Lessa <[EMAIL PROTECTED]> writes: > > IMHO, you should be using sets, not enums. Something like: > > If enums aren't supposed to work in that construction then the PEP > shouldn't specify that they work that way. Sorry, but

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Paul Rubin
Felipe Almeida Lessa <[EMAIL PROTECTED]> writes: > > print_members('shorter:', months_shorter_than_february) > > print_members('longer:', months_longer_than_february) > > IMHO, you should be using sets, not enums. Something like: If enums aren't supposed to work in that construction then

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Felipe Almeida Lessa
Em Seg, 2006-02-27 às 00:43 -0800, Paul Rubin escreveu: > def print_members(header, e): # print header, then members of enum e > print header > for m in e: > print '\t', str(m) > > months_longer_than_february = enum('jan', 'mar', 'apr', ) # etc > months_shorter_tha

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: Steven D'Aprano <[EMAIL PROTECTED]> writes: > What is an empty enum? An empty enum is an enum with no identifiers, just like an empty list is a list with no elements. > How and when would you use it? > The best I can come up with is that an empty enum

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Steven D'Aprano
Paul Rubin wrote: > Ben Finney <[EMAIL PROTECTED]> writes: > >>Enumerations with no values are meaningless. The exception >>``EnumEmptyError`` is raised if the constructor is called with no >>value arguments. > > > Why are empty enumerations not allowed? Empty sets, empty lists, > empty dicti

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Crutcher
This seems great, except why can't I compare strings? It seems too useful when dealing with user input, or parsing messages or config files. >>> Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') >>> Weekdays.mon.__cmp__('mon') 0 Additionaly, perhaps the call method of the enumerati

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Giovanni Bajo
Ben Finney wrote: > Values within an enumeration cannot be meaningfully compared except > with values from the same enumeration. The comparison operation > functions return ``NotImplemented`` [#CMP-NOTIMPLEMENTED]_ when a > value from an enumeration is compared against any value not from the > sa

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes: > Enumerations with no values are meaningless. The exception > ``EnumEmptyError`` is raised if the constructor is called with no > value arguments. Why are empty enumerations not allowed? Empty sets, empty lists, empty dictionaries are all allowed. I don't

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Giovanni Bajo
Kay Schluehr wrote: >> The enumerations specified in this PEP are instances of an ``enum`` >> type. Some alternative designs implement each enumeration as its own >> class, and a metaclass to define common properties of all >> enumerations. >> >> One motivation for having a class (rather than an

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Kay Schluehr
Ben Finney wrote: > Metaclass for creating enumeration classes > -- > > The enumerations specified in this PEP are instances of an ``enum`` > type. Some alternative designs implement each enumeration as its own > class, and a metaclass to define common pro

PEP 354: Enumerations in Python

2006-02-26 Thread Ben Finney
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: http://www.python.org/peps/pep-0354.html> Here is the reStructuredText source as it is today. Please discuss it here so I can see what issues people may have.