[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Ram Rachum

New submission from Ram Rachum:

I suggest making Enum members orderable, according to their order in the enum 
type. Currently trying to order them raises an exception:

 import enum
 class Number(enum.Enum):
... one = 1
... two = 2
... three = 3
 sorted((Number.one, Number.two))
Traceback (most recent call last):
  File pyshell#2, line 1, in module
sorted((Number.one, Number.two))
TypeError: unorderable types: Number()  Number()

If there's agreement from core developers that this is a good feature to add, 
I'll write a patch.

--
components: Library (Lib)
messages: 227678
nosy: cool-RR
priority: normal
severity: normal
status: open
title: Add ordering between `Enum` objects
type: enhancement
versions: Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Barry A. Warsaw

Barry A. Warsaw added the comment:

On Sep 27, 2014, at 02:28 PM, Ram Rachum wrote:

I suggest making Enum members orderable, according to their order in the enum
type.

Can you please provide a motivating use case?

--
nosy: +barry

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Why don't you use IntEnum?

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Ram Rachum

Ram Rachum added the comment:

Just because I want to be able to get the `int` value of an enum object, 
doesn't mean I want the enum object to *be* an `int`, which is what `IntEnum` 
means. I don't want it to be comparable to an int, I don't want to use 
arithmetic on it, and most importantly I don't want it to be equal to an enum 
object of a different type that happens to have the same int.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Barry A. Warsaw

Barry A. Warsaw added the comment:

On Sep 27, 2014, at 03:35 PM, Ram Rachum wrote:

Just because I want to be able to get the `int` value of an enum object,
doesn't mean I want the enum object to *be* an `int`, which is what `IntEnum`
means. I don't want it to be comparable to an int, I don't want to use
arithmetic on it, and most importantly I don't want it to be equal to an enum
object of a different type that happens to have the same int.

Okay, but that still doesn't explain the use case.  Also, why wouldn't an Enum
subclass, possibly using the ordered dictionary __members__ would not be
sufficient.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Barry A. Warsaw

Barry A. Warsaw added the comment:

https://docs.python.org/3/library/enum.html#orderedenum

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Ram Rachum

Ram Rachum added the comment:

My particular use case is that I have objects with a tuple of enum objects to 
each, and I want the tuple to be in canonical order rather than random, for 
convenience.

I can easily use a subclass, but I think it's general enough functionality for 
it to be included in the standard library.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
nosy: +ethan.furman

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22504] Add ordering between `Enum` objects

2014-09-27 Thread Ethan Furman

Ethan Furman added the comment:

Enums have a definition order to aid in the use-case of auto-numbering, and to 
make displays consistent.  However, the basic Enum type is unordered.

If you need/want your particular enum type to be ordered, mix-in the ordered 
magic methods.

--
assignee:  - ethan.furman
resolution:  - rejected
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22504
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com