[Python-Dev] Enumeration items: `type(EnumClass.item) is EnumClass` ?
Oscar Benjamin
oscar.j.benjamin at gmail.com
Mon Apr 29 21:52:47 CEST 2013
On 29 April 2013 20:04, Guido van Rossum <guido at python.org> wrote:
> On Mon, Apr 29, 2013 at 11:34 AM, Larry Hastings <larry at hastings.org> wrote:
>> What's the problem with overriding the isinstance checks? You mention it
>> but seem to assume it's a bad idea. That seems to me like it'd adequately
>> solve that problem with an acceptable level of magic.
>
> Depending on whether you are using isinstance() to check if an enum
> value belongs in the set of acceptable enums, or to check it it makes
> sense to call a certain method, you need isinstance() to behave
> differently.
Would it not be better to avoid using isinstance() for this?
I would have expected membership testing to use "Red in Colors" rather
than "isinstance(Red, Color)" like in this stackoverflow question
about an enum class:
http://stackoverflow.com/questions/10445819/overriding-contains-method-for-a-class
Oscar
More information about the Python-Dev
mailing list