[Python-Dev] PEP 435: pickling enums created with the functional API (original) (raw)
Eli Bendersky eliben at gmail.com
Tue May 7 17:47:41 CEST 2013
- Previous message: [Python-Dev] PEP 435: pickling enums created with the functional API
- Next message: [Python-Dev] PEP 435: pickling enums created with the functional API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, May 7, 2013 at 8:35 AM, Piotr Duda <duda.piotr at gmail.com> wrote:
2013/5/7 Ethan Furman <ethan at stoneleaf.us>: > On 05/07/2013 08:01 AM, Piotr Duda wrote: >> >> 2013/5/7 Ethan Furman <ethan at stoneleaf.us>: >>> >>> On 05/07/2013 07:48 AM, Piotr Duda wrote: >>>> >>>> >>>> >>>> What about adding simple syntax (I proposed this earlier, but no one >>>> commented) that take care of assigning name and module, something >>>> like: >>>> >>>> def name = expression >>>> >>>> which would be rough equivalent for: >>>> >>>> name = expression >>>> name.name = 'name' >>>> name.module = name >>> >>> >>> >>> How is that different from >>> >>> --> name = Enum('module.name', ... ) >>> >>> ? >> >> >> It's DRY. > > > How? You need to provide a complete example: > > Do you mean something like: > > --> def mymodule.Color('red green blue') >
def Color = Enum('red green blue')
It's an interesting idea, but as NIck suggested we should probably discuss it on the python-ideas list. It occurred to me while thinking about the duplication in "Color = Enum(Color, '...')" that if "Enum" had some magical way to know the name of the variable it's assigned to, the duplication would not be needed. But then, it obviously is fragile because what's this: somedict[key] = Enum(Color, ...).
A special syntax raises more questions though, because it has to be defined very precisely. Feel free to come up with a complete proposal to python-ideas, defining the interesting semantics.
Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130507/dcc11533/attachment.html>
- Previous message: [Python-Dev] PEP 435: pickling enums created with the functional API
- Next message: [Python-Dev] PEP 435: pickling enums created with the functional API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]