[Python-Dev] Enum: subclassing? (original) (raw)
Eli Bendersky eliben at gmail.com
Thu May 2 00:25:59 CEST 2013
- Previous message: [Python-Dev] Enum: subclassing?
- Next message: [Python-Dev] Enum: subclassing?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Good point. I think this may be just an artifact of the implementation - PEP 435 prohibits implicit conversion to integers for non-IntEnum enums. Since IntEnum came into existence, there's no real need for int-opearbility of other enums, and their values can be arbitrary anyway.
Ethan - unless I'm missing something, int should probably be removed. The reason int is there is because pure Enums should be using plain ints as their value 95% or more of the time, and being able to easily convert to a real int for either database storage, wire transmission, or C functions is a Good Thing.
Yes, but the .value attribute makes it "easy enough". If you have foo which is of type SomeEnum, all you need (if you know for sure it has int values) is to pass foo.value instead of just foo to places that do int conversion.
Relying on init is unsafe in the general case because enums can have non-int values, or mixed values, or whatever. You only want "true int conversion" in rare cases for which IntEnum exists.
Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130501/a8d7e0c0/attachment-0001.html>
- Previous message: [Python-Dev] Enum: subclassing?
- Next message: [Python-Dev] Enum: subclassing?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]