[Python-ideas] Enums

Guido van Rossum guido at python.org
Thu Jul 28 00:49:08 CEST 2011

On Wed, Jul 27, 2011 at 3:24 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> But the grouping behaviour? I really don't see a lot of value in that
> - just boilerplate. We don't write bool.True and bool.False, we write
> True and False.

I have to agree with that. Enums can live in a module (together with
stuff that uses them) or in a class (if all the uses are limited to
that class); they don't need an extra namespace of their own.

The standard examples using homonyms in unrelated enums are typically
missing the fact that Python doesn't really have *global* variables --
only "module-global", which is really quite narrowly scoped.

If a single module or package is exporting so many enums that extra
scoping is considered useful, it's easy enough to introduce an extra
namespace using existing mechanisms (e.g. a class or a submodule).

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list