[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)
Ethan Furman ethan at stoneleaf.us
Fri Apr 12 23:19:53 CEST 2013
- Previous message: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
- Next message: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 04/12/2013 02:06 PM, Eli Bendersky wrote:
On Fri, Apr 12, 2013 at 1:52 PM, R. David Murray wrote: >>> import enum >>> class Foo(enum.Enum): ... aa = 1 ... bb = 2 ... cc = 'hi' >>> Foo Traceback (most recent call last): File "", line 1, in File "./enum.py", line 103, in repr for k in sorted(cls.enums))) TypeError: unorderable types: str() < int()
I actually think that having values with different types within a single Enum is conceptually wrong and should be disallowed at creation time. With enums, you either care or don't care about their actual value. If you don't care (the most common use case of an enum, IMHO), then no problem here. If you do care, then it's probably for very specific reasons most of which are solved by IntEnum. I can't imagine why someone would need differently typed values in a single enum - this just seems like a completely inappropriate use of an enum to me.
+1 (on disallowing the mixed type enum, not the valueless enum being more common ;)
- Previous message: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
- Next message: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]