[Python-ideas] Allow Enum members to refer to each other during execution of body

Ethan Furman ethan at stoneleaf.us
Fri Jul 12 00:00:21 CEST 2013


On 07/11/2013 02:07 PM, Antony Lee wrote:
> On Wednesday, July 10, 2013 6:52:24 PM UTC-7, stoneleaf wrote:
>> On 07/10/2013 03:47 PM, Antony Lee wrote:
>>>
>>> Forward references are now implemented (https://github.com/anntzer/enum <https://github.com/anntzer/enum>).
>>
>> Do they work with a custom __new__ ?  __init__ ?
>
> In the current version, they work with a custom __init__ (though of course, as long as the actual arguments that need to
> be passed to __init__ are provided, the pre-declared members are just "empty").  They do not work with a custom __new__
> (not sure how I could make this work, given that at declaration time an "empty" member needs to be created but we don't
> know what arguments we need to pass to __new__...).
> As a side effect, however, the whole patch adds a new requirement: custom __new__s must be defined before the members
> themselves; otherwise they won't be called, for the same reason as above: if I don't know what __new__ is, I can't call
> it...

Hmm.  Well, at this point I can offer kudos for getting it this far, but that's about it.  The use-case this addresses 
seems fairly rare, and is definitely not a typical enumeration, and can be solved fairly easily with some extra 
post-processing code on a per-enumeration basis.

--
~Ethan~


More information about the Python-ideas mailing list