[Python-ideas] constant/enum type in stdlib

Jim Jewett jimjjewett at gmail.com
Thu Jan 31 17:10:33 CET 2013


On Tue, Jan 29, 2013 at 6:50 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> FWIW, since that last discussion, I've switched to using strings for
> my special constants, dumping them in a container if I need some kind
> of easy validity checking or iteration.

Unfortunately, some of the problems with that involve unicode
normalization, and won't show up in English.

Python has defined a normalization for identifiers; this normalization
does not apply to quoted strings.  Essentially, this is the same
problem string exceptions caused, except that it (sometimes) applies
to '==' as well as to 'is'.

Essentially, we want the simplicity of:

    color=enum(red, green, blue)

except that we *also* want to able to compare the symbols to (int or
str) constants, and to decide when they will be equal.  I don't see
any good way to support:

    color=enum(red=15, green, blue)

without requiring either that strings be used instead of symbols, or
that later entries be explicitly initialized.

-jJ



More information about the Python-ideas mailing list