[Python-Dev] PEP 435: initial values must be specified? Yes (original) (raw)
Tim Delaney timothy.c.delaney at gmail.com
Mon May 6 00:34:54 CEST 2013
- Previous message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Next message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 6 May 2013 08:00, Guido van Rossum <guido at python.org> wrote:
On Sun, May 5, 2013 at 2:55 PM, Tim Delaney <timothy.c.delaney at gmail.com> wrote: > So long as I can get one of the requirements documented to implement an > auto-number syntax I'll be happy enough with stdlib enums I think.
Specifically what do you want the PEP to promise?
It was mentioned in the other threads, but the requirement is either:
- That the dictionary returned from .prepare provide a way to obtain the enum instance names once it's been populated (e.g. once it's been passed as the classdict to new). The reference implementation provides a _enum_names list attribute. The enum names need to be available to a metaclass subclass before calling the base metaclass new.
OR
- A way for subclasses of Enum to modify the value before it's assigned to the actual enum - see the PEP 435 reference implementation - discussion thread where I modified the reference implementation to give enum instances 2-phase construction, passing the value to Enum.init. This way is more limited, as you need to use an appropriate mix-in type which puts certain constraints on the behaviour of the enum instances (e.g. they have to be int instances for auto-numbering). The implementation is also more complex, and as noted in that thread, init might not be appropriate for an Enum.
Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130506/f929459b/attachment.html>
- Previous message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Next message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]