[Python-ideas] proper naming of Enum members
Barry Warsaw
barry at python.org
Mon Jul 18 14:35:03 EDT 2016
On Jul 18, 2016, at 08:17 AM, Ethan Furman wrote:
>Take the name "NewYear": if it had been a global constant I would have named
>it "NEWYEAR"; if it had been a normal class attribute I would have named it
>"new_year"; however, being an Enum member, it is neither of those things.
Since in my code at least, I always include the enum class name at the call
site, underscore_words for enum members is just fine.
class Action(Enum):
hold = 0
reject = 1
discard = 2
accept = 3
defer = 4
...
if action in (Action.defer, Action.hold):
# ...
elif action is Action.discard:
# ...
elif action is Action.reject:
# ...
elif action is Action.accept:
# ...
and so on. Make the code less shifty :).
Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160718/d894a8d9/attachment.sig>
More information about the Python-ideas
mailing list