A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-June/127132.html below:

[Python-Dev] backported Enum

[Python-Dev] backported EnumNick 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.

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4