Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Piotr Duda
2013/4/26 Nick Coghlan ncogh...@gmail.com On Fri, Apr 26, 2013 at 8:29 AM, Barry Warsaw ba...@python.org wrote: On Apr 25, 2013, at 03:19 PM, Guido van Rossum wrote: Clearly this is a trick question. :-) A bit, yes. :) I was told when this was brought up previously (a week ago?) that

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Ethan Furman
On 04/25/2013 10:30 PM, Nick Coghlan wrote: Alternatively, we can flip it around and require that each enum definition nominate an expected value type (defaulting to int) and only convert class attributes that are instances of that type to instances of the enum class. I think this option

Re: [Python-Dev] NoneType(None) raises exception

2013-04-26 Thread Antoine Pitrou
On Thu, 25 Apr 2013 16:09:41 -0700 Ethan Furman et...@stoneleaf.us wrote: We just fixed NoneType() to return None instead of raising an exception. Another use-case for calling NoneType is working with ORMs: result = [] for field in row: type = get_type(field) # returns int,

Re: [Python-Dev] NoneType(None) raises exception

2013-04-26 Thread Lennart Regebro
On Fri, Apr 26, 2013 at 1:09 AM, Ethan Furman et...@stoneleaf.us wrote: We just fixed NoneType() to return None instead of raising an exception. Another use-case for calling NoneType is working with ORMs: result = [] for field in row: type = get_type(field) # returns int, bool,

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Greg Ewing
Steven D'Aprano wrote: I don't think iscallable will work, since that descriptors like staticmethod and classmethod aren't callable. Nor are properties. Hmmm, maybe we should look for a __get__ method as well? Enums of descriptors would seem to fall into the seriously-weird category as well.

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Greg Ewing
Piotr Duda wrote: There is at least one more problem, enum inheritance, given: class Colors(Enum): red = 1 green = 2 blue = 3 class MoreColors(Color): cyan = 4 magenta = 5 yellow = 6 what type is MoreColors.red? Given the implementation we're considering, it would probably be

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Serhiy Storchaka
26.04.13 11:00, Greg Ewing написав(ла): However, there's a worse problem with defining enum inheritance that way. The subtype relation for extensible enums works the opposite way to that of classes. To see this, imagine a function expecting something of type Colors. It knows what to do with

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Steven D'Aprano
On 26/04/13 18:00, Greg Ewing wrote: However, there's a worse problem with defining enum inheritance that way. The subtype relation for extensible enums works the opposite way to that of classes. To see this, imagine a function expecting something of type Colors. It knows what to do with red,

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread MRAB
On 26/04/2013 06:21, Ethan Furman wrote: On 04/25/2013 08:14 PM, Greg wrote: On 26/04/2013 1:28 p.m., Ethan Furman wrote: Interesting idea, but why does Day(3) have to be disallowed to make it work? Because it's ambiguous. Which day of the week is number 3? It depends on where you start.

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Larry Hastings
On 04/26/2013 12:34 AM, Greg Ewing wrote: Or if, as Guido says, the only sensible things to use as enum values are ints and strings, just leave anything alone that isn't one of those. The standard Java documentation on enums: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

[Python-Dev] Summary of Python tracker Issues

2013-04-26 Thread Python tracker
ACTIVITY SUMMARY (2013-04-19 - 2013-04-26) Python tracker at http://bugs.python.org/ To view or respond to any of the issues listed below, click on the issue. Do NOT respond to this message. Issues counts and deltas: open3949 (+21) closed 25674 (+32) total 29623 (+53) Open issues

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Serhiy Storchaka
26.04.13 18:50, Larry Hastings написав(ла): On 04/26/2013 12:34 AM, Greg Ewing wrote: Or if, as Guido says, the only sensible things to use as enum values are ints and strings, just leave anything alone that isn't one of those. The standard Java documentation on enums:

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Ethan Furman
On 04/26/2013 08:50 AM, Larry Hastings wrote: FWIW I'm +0.5 on the enum metaclass ignores callables and descriptors. This seems reasonably Pythonic, much more so than ignore everything except ints and strings. And as long as we're special-casing it I think we should opt for flexibility.

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Guido van Rossum
On Fri, Apr 26, 2013 at 10:33 AM, Glenn Linderman v+pyt...@g.nevcal.com wrote: On 4/25/2013 9:19 PM, Guido van Rossum wrote: On Thu, Apr 25, 2013 at 8:39 PM, Glenn Linderman v+pyt...@g.nevcal.com wrote: an enumeration of objects whose class defines __call__ would not be so weird.

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Larry Hastings
On 04/26/2013 09:27 AM, Serhiy Storchaka wrote: 26.04.13 18:50, Larry Hastings написав(ла): The standard Java documentation on enums: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html This example requires more than features discussed here. It requires an enum constructor.

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Ethan Furman
On 04/26/2013 09:27 AM, Serhiy Storchaka wrote: 26.04.13 18:50, Larry Hastings написав(ла): On 04/26/2013 12:34 AM, Greg Ewing wrote: Or if, as Guido says, the only sensible things to use as enum values are ints and strings, just leave anything alone that isn't one of those. The standard

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Glenn Linderman
On 4/25/2013 9:19 PM, Guido van Rossum wrote: On Thu, Apr 25, 2013 at 8:39 PM, Glenn Linderman v+pyt...@g.nevcal.com wrote: an enumeration of objects whose class defines __call__ would not be so weird. Seriously? You'd complexificate the basic usage in order to cater for such an esoteric use

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Eli Bendersky
On Fri, Apr 26, 2013 at 10:36 AM, Guido van Rossum gu...@python.org wrote: On Fri, Apr 26, 2013 at 10:33 AM, Glenn Linderman v+pyt...@g.nevcal.com wrote: On 4/25/2013 9:19 PM, Guido van Rossum wrote: On Thu, Apr 25, 2013 at 8:39 PM, Glenn Linderman v+pyt...@g.nevcal.com wrote: an

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Serhiy Storchaka
26.04.13 11:00, Greg Ewing написав(ла): However, there's a worse problem with defining enum inheritance that way. The subtype relation for extensible enums works the opposite way to that of classes. To see this, imagine a function expecting something of type Colors. It knows what to do with

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Serhiy Storchaka
26.04.13 05:13, Nick Coghlan написав(ла): With a merged design, it becomes *really* hard to give the instances custom behaviour, because the metaclass will somehow have to differentiate between namespace entries that are intended to be callables, and those which are intended to be instances of

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Serhiy Storchaka
Thank you for your answers, Barry. Eli already answered me most of my questions. 20.04.13 22:18, Barry Warsaw написав(ла): On Apr 13, 2013, at 11:31 AM, Serhiy Storchaka wrote: The str and repr of the enumeration class also provides useful information:: print(Colors) Colors

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Guido van Rossum
On Fri, Apr 26, 2013 at 11:17 AM, Eli Bendersky eli...@gmail.com wrote: On Fri, Apr 26, 2013 at 10:36 AM, Guido van Rossum gu...@python.org wrote: On 4/25/2013 9:19 PM, Guido van Rossum wrote: I think you've lost track of the Zen of Python. I feel that this thread has lost track of it long

[Python-Dev] Generator finalization and reference cycles

2013-04-26 Thread Antoine Pitrou
Hello, I have proposed a new generator finalization scheme in http://bugs.python.org/issue17807: it removes the tp_del from generator objects, instead electing to cleanup the generator (equivalent of calling close()) in the frame's tp_clean function. This way, generators with a try / finally

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Eli Bendersky
On Fri, Apr 26, 2013 at 2:41 PM, Guido van Rossum gu...@python.org wrote: On Fri, Apr 26, 2013 at 11:17 AM, Eli Bendersky eli...@gmail.com wrote: On Fri, Apr 26, 2013 at 10:36 AM, Guido van Rossum gu...@python.org wrote: On 4/25/2013 9:19 PM, Guido van Rossum wrote: I think you've lost

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Greg Ewing
Guido van Rossum wrote: If we had access to the syntax used for the definition, this would be simple: assignments define items, def statements define methods. But at run time we only see the final object resulting from the definition, Another way we could tell the difference is if the def

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Greg Ewing
Eli Bendersky wrote: There's a conceptual difference between a value of an enumeration and a collection of such values. Not if you think of an enum as a type and a type as defining a set of values. From that point of view, the enum itself is already a collection of values, and introducing

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Glenn Linderman
On 4/26/2013 6:22 PM, Greg Ewing wrote: Guido van Rossum wrote: If we had access to the syntax used for the definition, this would be simple: assignments define items, def statements define methods. But at run time we only see the final object resulting from the definition, Another way we

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Ethan Furman
On 04/26/2013 06:37 PM, Greg Ewing wrote: Eli Bendersky wrote: There's a conceptual difference between a value of an enumeration and a collection of such values. Not if you think of an enum as a type and a type as defining a set of values. From that point of view, the enum itself is already

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Ethan Furman
On 04/26/2013 11:17 AM, Eli Bendersky wrote: I feel that this thread has lost track of it long ago. Some time back in the Enum discussions (some 350 messages ago or so), there was a proposal to have this: class Color(Enum): RED, BLUE, GREEN By doing some crazy-cool shenanigans. Although

Re: [Python-Dev] Destructors and Closing of File Objects

2013-04-26 Thread Nikolaus Rath
Guido van Rossum gu...@python.org writes: On Monday, April 15, 2013, Nikolaus Rath wrote: Brian Curtin br...@python.org javascript:; writes: On Fri, Apr 12, 2013 at 12:04 AM, Nikolaus Rath nikol...@rath.orgjavascript:; wrote: [ Note: I already asked this on

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Nikolaus Rath
Steven D'Aprano st...@pearwood.info writes: On 26/04/13 13:22, Greg wrote: On 26/04/2013 3:12 p.m., Glenn Linderman wrote: On 4/25/2013 7:49 PM, Nick Coghlan wrote: You couldn't create an enum of callables, but that would be a seriously weird thing to do anyway But aren't all classes

Re: [Python-Dev] Destructors and Closing of File Objects

2013-04-26 Thread Guido van Rossum
There are no guarantees in life. On the other hand: Don't worry, be happy. On Fri, Apr 26, 2013 at 7:39 PM, Nikolaus Rath nikol...@rath.org wrote: Guido van Rossum gu...@python.org writes: On Monday, April 15, 2013, Nikolaus Rath wrote: Brian Curtin br...@python.org javascript:; writes: On

Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013-04-26 Thread Ethan Furman
On 04/26/2013 07:29 PM, Glenn Linderman wrote: On 4/26/2013 6:22 PM, Greg Ewing wrote: Guido van Rossum wrote: If we had access to the syntax used for the definition, this would be simple: assignments define items, def statements define methods. But at run time we only see the final object