Message227700
On Sep 27, 2014, at 04:15 PM, Ram Rachum wrote:
>The main principle is: If something has an important property (in this case
>an enum object's numerical value), it should be publicly exposed.
I think this is a misunderstanding. Only IntEnum members have a defined
numerical value. Base Enum members have no inherent value semantics except
their existence. The *syntax* of using integers for values is simply a
convention and one that's not even necessary for Enums to work properly.
Enum members are also defined to be unordered, so their serial number is
meaningless. The fact that __members__ is an ordered dictionary is a
convenient implementation detail that's only exposed in the API to support
iteration over all members including aliases.
Let me say specifically that I am opposed to int() for coercion for
non-IntEnums because Enum values can be anything. Likewise, member.number is
also a misnomer in this case:
>>> from enum import Enum
>>> class Colors(Enum):
... a = 'a'
... b = 'b'
... c = 'c'
...
>>> Colors.a is Colors.b
False
>>> Colors.a is Colors.a
True
I think using IntEnums or a subclass to provide a convenient wrapper around
__members__ iteration is the only thing that makes sense here, but I still
don't think the stdlib needs to support it. IMHO, this is a case where adding
to the public stdlib API would provide more complexity for little common
benefit. |
|
Date |
User |
Action |
Args |
2014-09-27 16:46:11 | barry | set | recipients:
+ barry, eli.bendersky, cool-RR, ethan.furman |
2014-09-27 16:46:11 | barry | link | issue22505 messages |
2014-09-27 16:46:11 | barry | create | |
|