[Python-ideas] Naming convention for Enums

Chris Angelico rosuav at gmail.com
Thu Sep 15 14:14:56 EDT 2016


On Fri, Sep 16, 2016 at 4:06 AM, Guido van Rossum <guido at python.org> wrote:
>> Sometimes they function as integer constants (esp IntEnum), and
>> sometimes more as just arbitrary values. See the examples in the docs
>> [1] for Color and Mood, where the exact value is immaterial, just as
>> long as Color.red is not Color.blue. Even though they happen to have
>> integer values, they're not intended to be used as actual integers.
>> For those cases, it's not as clear that they ought to be Color.RED and
>> Color.BLUE - it's equally acceptable to have them in lowercase.
>
> I disagree. The whole point of an enum is to define a new *kind* of
> constant. Clearly RED and BLUE are new constants. (The uppercase
> convention is not just for giving names to literals -- that's not what
> "constant" means.)

Well, my view was largely colored [1] by the official docs. Your view
is broadly the same as my ideal preference, just without the caveats
and flexibility of accepting it the other way. So should the docs be
updated to upper-case everything?

With or without an actual PEP 8 change, that would send a strong
message to the community. I'm sure I'm not the only person who looks
at official examples as a style guide as well as a syntax demo.

ChrisA

[1] Sorry [2], that pun was just terrible
[2] Actually I'm not sorry. But the pun was still terrible.


More information about the Python-ideas mailing list