[Python-ideas] Fwd: Allow Enum members to refer to each other during execution of body
Ethan Furman
ethan at stoneleaf.us
Fri Jul 19 21:34:31 CEST 2013
On 07/14/2013 02:36 PM, Antony Lee wrote:
> Is there any specific reason why you do not wish to change the behavior of Enum to this one (which does seem more
> logical to me)? The patch is fairly simple in its logic (compared to the rest of the implementation, at least...),
> and I could even change it to remove the requirement of defining __new__ before the members as long as there are no
> references to other members (because as long as there are no references to other members, I obviously don't need to
> actually create the members), thus making it fully compatible with the current version.
My apologies for the delay in replying.
Getting Enum into the stdlib was a very careful balancing act:
- Make it powerful enough to meet most needs as-is
- Make it extensible enough that custom enumerations could be
easily implemented
- Make it simple enough to not create a large cognitive burden
How this relates to your patch:
1) With your patch, referencing another enum member either returns
the member itself (pure Enum), or the value of the Enum (mixed
Enum) -- which means two different behaviors from the same
syntax.
2) The patch fails with the pure Enum with auto-numbering test case.
It fails because __new__ is looking at the __member__ data
structure which is empty for the duration of __prepare__. While
work arounds are possible, they would not be simpler, or even as
simple.
Summary: The resulting behavior is inconsistent, and the complexity added to the code, but mostly to the mind, is much
greater than the minor benefit.
--
~Ethna
More information about the Python-ideas
mailing list