[Python-ideas] Naming convention for Enums

Guido van Rossum guido at python.org
Wed Sep 14 10:43:51 EDT 2016

I recommend naming all enums UPPER_CASE. They're constants (within a
namespace) and that's the rule for constants. It's helpful for the
reader of the code to realize what they are when passed around -- they
have a similar status to literal constants, you know they stand for a
unique value and not for some computed quantity.

On Wed, Sep 14, 2016 at 4:58 AM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 14 September 2016 at 12:51, Chris Angelico <rosuav at gmail.com> wrote:
>> Perhaps the advice needs to be along the lines of: Decide what the
>> purpose of the enum is, and follow a naming convention accordingly.
>> Uppercase if you're basically making constants; lowercase if you're
>> not; etcetera.
> Agreed - it's not clear to me that a prescriptive rule has much
> benefit here. The OP said "I believe that we need to make a decision
> as no decision is somewhat worse and causes a lot of confusion" -
> personally, I don't agree, I think it's fine to leave this to the
> individual.
> And of course, no matter how many times we stress that any rules we
> add are "only recommendations", projects like pycodestyle will add
> checks (as they should) and then projects that mandate a clean run of
> a style checker will treat the rule as mandatory.
> So I'm basically -1 on a PEP 8 rule at this stage, but if we have to
> have one, I agree that it should say something along the lines of
> "depends on how you're using the enum".
> Paul
> PS FWIW, I tend to think of enums as named constants, and so would
> typically use uppercase, not lowercase. But I wouldn't like to impose
> that on everyone :-)
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

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

More information about the Python-ideas mailing list