Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-09 Thread Eli Bendersky
On Thu, May 9, 2013 at 9:31 AM, Barry Warsaw wrote: > On May 09, 2013, at 09:24 AM, Guido van Rossum wrote: > > >+1. This is a good one. While adding module=__name__ is actually more > >typing than passing __name__ + '.Color' as the class name, the current > >proposal (parsing for dots) makes it

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-09 Thread Barry Warsaw
On May 09, 2013, at 09:24 AM, Guido van Rossum wrote: >+1. This is a good one. While adding module=__name__ is actually more >typing than passing __name__ + '.Color' as the class name, the current >proposal (parsing for dots) makes it very attractive to do the wrong thing >and hardcode the module

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-09 Thread Guido van Rossum
On Thu, May 9, 2013 at 7:17 AM, Nick Coghlan wrote: > As Eric noted on the tracker issue, a keyword only "module" argument may > be a better choice for both than allowing dotted names. A separate > parameter is easier to use with __name__ to avoid hardcoding the module > name. +1. This is a goo

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-09 Thread Nick Coghlan
On 9 May 2013 13:48, "Eli Bendersky" wrote: > > > > > On Tue, May 7, 2013 at 8:03 AM, Nick Coghlan wrote: >> >> On Tue, May 7, 2013 at 11:34 PM, Eli Bendersky wrote: >> > One of the contended issues with PEP 435 on which Guido pronounced was the >> > functional API, that allows created enumerati

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-08 Thread Eli Bendersky
On Tue, May 7, 2013 at 8:03 AM, Nick Coghlan wrote: > On Tue, May 7, 2013 at 11:34 PM, Eli Bendersky wrote: > > One of the contended issues with PEP 435 on which Guido pronounced was > the > > functional API, that allows created enumerations dynamically in a manner > > similar to namedtuple: > >

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-08 Thread Nick Coghlan
On 8 May 2013 01:26, "Antoine Pitrou" wrote: > > Le Wed, 8 May 2013 01:03:38 +1000, > Nick Coghlan a écrit : > > > > What if there was a variant of the class statement that bound the > > result of a function call rather than using the normal syntax: > > > > class Animal from enum.Enum(members

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Eli Bendersky
On Tue, May 7, 2013 at 6:00 PM, Steven D'Aprano wrote: > On 07/05/13 23:34, Eli Bendersky wrote: > >> One of the contended issues with PEP 435 on which Guido pronounced was the >> functional API, that allows created enumerations dynamically in a manner >> similar to namedtuple: >> >>Color = E

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Steven D'Aprano
On 07/05/13 23:34, Eli Bendersky wrote: One of the contended issues with PEP 435 on which Guido pronounced was the functional API, that allows created enumerations dynamically in a manner similar to namedtuple: Color = Enum('Color', 'red blue green') The biggest complaint reported against th

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Larry Hastings
On 05/07/2013 08:47 AM, Eli Bendersky wrote: 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. [...] A special syntax raises more questions though, because it has to be defined very precisely. Feel

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Michael Urman
On Tue, May 7, 2013 at 8:34 AM, Eli Bendersky wrote: > According to an earlier discussion, this is works on CPython, PyPy and > Jython, but not on IronPython. The alternative that works everywhere is to > define the Enum like this: > > Color = Enum('the_module.Color', 'red blue green') > > The

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Eli Bendersky
On Tue, May 7, 2013 at 9:14 AM, Antoine Pitrou wrote: > Le Tue, 7 May 2013 08:44:46 -0700, > Eli Bendersky a écrit : > > > > 4) Using _getframe(N) here seems like an overkill to me. > > > > > > It's not just overkill, it's fragile - it only works if you call the > > > constructor directly. If y

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Antoine Pitrou
Le Tue, 7 May 2013 08:44:46 -0700, Eli Bendersky a écrit : > > > 4) Using _getframe(N) here seems like an overkill to me. > > > > It's not just overkill, it's fragile - it only works if you call the > > constructor directly. If you use a convenience function in a utility > > module, it will try t

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Ethan Furman
On 05/07/2013 08:03 AM, Nick Coghlan wrote: On Tue, May 7, 2013 at 11:34 PM, Eli Bendersky wrote: 4) Using _getframe(N) here seems like an overkill to me. It's not just overkill, it's fragile - it only works if you call the constructor directly. If you use a convenience function in a utility

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Eli Bendersky
On Tue, May 7, 2013 at 8:35 AM, Piotr Duda wrote: > 2013/5/7 Ethan Furman : > > On 05/07/2013 08:01 AM, Piotr Duda wrote: > >> > >> 2013/5/7 Ethan Furman : > >>> > >>> On 05/07/2013 07:48 AM, Piotr Duda wrote: > > > > What about adding simple syntax (I proposed this earlier, b

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Xavier Morel
On 2013-05-07, at 17:03 , Nick Coghlan wrote: > > Specifically, what I'm talking about is some kind of implicit context > similar to the approach the decimal module uses to control operations > on Decimal instances. Wouldn't it be a good occasion to add actual, full-fledged and correctly implemen

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Eli Bendersky
On Tue, May 7, 2013 at 8:03 AM, Nick Coghlan wrote: > On Tue, May 7, 2013 at 11:34 PM, Eli Bendersky wrote: > > One of the contended issues with PEP 435 on which Guido pronounced was > the > > functional API, that allows created enumerations dynamically in a manner > > similar to namedtuple: > >

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Piotr Duda
2013/5/7 Ethan Furman : > On 05/07/2013 08:01 AM, Piotr Duda wrote: >> >> 2013/5/7 Ethan Furman : >>> >>> 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, s

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Ethan Furman
On 05/07/2013 08:01 AM, Piotr Duda wrote: 2013/5/7 Ethan Furman : 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

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Antoine Pitrou
Le Wed, 8 May 2013 01:03:38 +1000, Nick Coghlan a écrit : > > What if there was a variant of the class statement that bound the > result of a function call rather than using the normal syntax: > > class Animal from enum.Enum(members="dog cat bear") Apparently you're trying hard to invent sy

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Nick Coghlan
On Wed, May 8, 2013 at 12:53 AM, Ethan Furman wrote: > 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

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Nick Coghlan
On Tue, May 7, 2013 at 11:34 PM, Eli Bendersky wrote: > One of the contended issues with PEP 435 on which Guido pronounced was the > functional API, that allows created enumerations dynamically in a manner > similar to namedtuple: > > Color = Enum('Color', 'red blue green') > > The biggest compl

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Piotr Duda
2013/5/7 Ethan Furman : > 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: >> >

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Ethan Furman
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.__mod

Re: [Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Piotr Duda
2013/5/7 Eli Bendersky : > > 4) Using _getframe(N) here seems like an overkill to me. What we really need > is just the module in which the current execution currently is (i.e. the > metaclass's __new__ in our case). Would it make sense to add a new function > somewhere in the stdlib of 3.4 (in sys

[Python-Dev] PEP 435: pickling enums created with the functional API

2013-05-07 Thread Eli Bendersky
One of the contended issues with PEP 435 on which Guido pronounced was the functional API, that allows created enumerations dynamically in a manner similar to namedtuple: Color = Enum('Color', 'red blue green') The biggest complaint reported against this API is interaction with pickle. As promi