Message400236
Firstly (or Zeroithly ;) my apologies for not noticing this earlier.
In the functional API section:
------------------------------
The reason for defaulting to 1 as the starting number and not 0 is that 0 is False in a boolean sense, but enum members all evaluate to True.
---
To the best of my knowledge, Python Enums are different from other languages' enums in several respects; apparently this is one of them. Having the default first value be 1 has been there since the beginning, and isn't going to change now.
Rather than allowing numbers to be assigned using the function that says the assigned number doesn't matter, I would rather add `start=x` in the header, the way I have it in `aenum`:
from aenum import Enum, auto
class ZeroEnum(Enum, start=0):
nothing = auto()
something = auto()
list(ZeroEnum)
# [<ZeroEnum.nothing: 0>, <ZeroEnum.something: 1>]
class ZeroBaseEnum(Enum, start=0):
pass
class ZeroEnum2(ZeroBaseEnum):
nothing = auto()
something = auto()
list(ZeroEnum2)
# [<ZeroEnum2.nothing: 0>, <ZeroEnum2.something: 1>]
Whether the `0` goes in the header, or in auto (which it isn't), people will still need to read the docs to find out about it (unless somebody asks an SO question, of course). |
|
Date |
User |
Action |
Args |
2021-08-24 20:43:44 | ethan.furman | set | recipients:
+ ethan.furman, eric.smith, veky, David Rebbe2 |
2021-08-24 20:43:44 | ethan.furman | set | messageid: <1629837824.32.0.00591357302214.issue44993@roundup.psfhosted.org> |
2021-08-24 20:43:44 | ethan.furman | link | issue44993 messages |
2021-08-24 20:43:44 | ethan.furman | create | |
|