[Python-Dev] backported Enum

Nick Coghlan ncoghlan at gmail.com
Sat Jun 29 12:21:36 CEST 2013

On 29 June 2013 06:30, Ethan Furman <ethan at stoneleaf.us> wrote:
>> I would also not be shocked if some people expect failed value
>> lookups to raise an IndexError, though I expect they would
>> adapt if they get something else that makes sense.
>> Would it be wrong to create an EnumError that subclasses
>> (ValueError, KeyError, AttributeError) and to raise that
>> subclass from everything but _StealthProperty and _get_mixins?
> Wouldn't bother me; I'm not sure what the bar is for adding new exceptions,
> though.

I'd actually do something a bit more complex, but also cleaner from a
type system perspective:

    class EnumError(Exception): pass
    class EnumValueError(EnumError, ValueError): pass
    class EnumAttributeError(EnumError, AttributeError): pass
    class EnumKeyError(EnumError, KeyError): pass

However, it's probably not necessary. The value lookup API should just
document clearly which exception it throws.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list