[Python-Dev] constant/enum type in stdlib
solipsis at pitrou.net
Tue Nov 23 16:01:06 CET 2010
Le mardi 23 novembre 2010 à 08:52 -0600, Benjamin Peterson a écrit :
> 2010/11/23 Antoine Pitrou <solipsis at pitrou.net>:
> > On Tue, 23 Nov 2010 14:24:18 +0000
> > Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> >> Well, for backwards compatibility reasons the new constants would have
> >> to *behave* like the old ones (including having the same underlying
> >> value and comparing equal to it).
> >> In many cases it is *likely* that subclassing int is a better way of
> >> achieving that. Actually looking through the standard library to
> >> evaluate it is the only way of confirming that.
> >> Another API, that reduces the duplication of creating the enum and
> >> setting the names, could be something like:
> >> make_enums("Names", "NAME_ONE NAME_TWO NAME_THREE", base_type=int,
> >> module=__name__)
> >> Using __name__ we can set the module globals in the call to make_enums.
> > I don't understand why people insist on calling that an "enum". enum is
> > a C legacy and it doesn't bring anything useful as I can tell. Instead,
> > just assign the values explicitly.
> The concept of a "enumeration" of values is still useful outside its
> stunted C incarnation.
Well, it is easy to assign range(N) to a tuple of names when desired. I
don't think an automatically-enumerating constant generator is needed.
More information about the Python-Dev