Re: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

2013年4月12日 08:31:29 -0700

On 2013年4月12日 11:02:54 -0400, Barry Warsaw <[email protected]> wrote:
> On Apr 12, 2013, at 03:31 PM, Dirkjan Ochtman wrote:
> >On Fri, Apr 12, 2013 at 2:55 PM, Eli Bendersky <[email protected]> wrote:
> >> >>> Colors.blue >= Colors.green
> >> Traceback (most recent call last):
> >> ...
> >> NotImplementedError
> >
> >I like much of this PEP, but the exception type for this case seems
> >odd to me. Wouldn't a TypeError be more appropriate here?
> >
> >Somewhat like this:
> >
> >>>> 'a' - 'b'
> >Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> >TypeError: unsupported operand type(s) for -: 'str' and 'str'
> 
> Interesting. I'm having a hard time articulating why, but NotImplementedError
> just feels more right to me in this case.
I think TypeError is more consistent with the rest of Python:
>>> object() < object()
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: unorderable types: object() < object()
You get that automatically if you return NotImplemented from the
comparison methods. I don't think you should be explicitly raising
NotImplemented.
--David
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to