[Python-Dev] PEP 435: initial values must be specified? Yes (original) (raw)
Tim Delaney timothy.c.delaney at gmail.com
Mon May 6 01:14:36 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:55, Eli Bendersky <eliben at gmail.com> wrote:
1. 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 enumnames list attribute. The enum names need to be available to a metaclass subclass before calling the base metaclass new.
So your preferred solution is (1), which requires exposing the metaclass and an attribute publicly? I have to ask - to what end? What is the goal of this? To have an AutoNumberedEnum which is guaranteed to be compatible with stdlib's Enum? My preferred solution is 1 (for the reason mentioned above) but it does not require exposing the metaclass publically (that's obtainable via type(Enum)). It does require a way to get the enum names before calling the base metaclass new, but that does not necessarily imply that I'm advocating exposing _enum_names (or at least, not directly).
My preferred way would probably be a note that the dictionary returned from the enum metaclass prepare implements an enum_names() or maybe enum_names() method which returns an iterator over the enum instance names in definition order. The way this is implemented by the dictionary would be an implementation detail.
The enum metaclass new needs access to the enum instance names in definition order, so I think making it easily available to enum metaclass subclasses as well just makes sense.
Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130506/65589332/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 ]