How to subclass a built-in int type and prevent comparisons

Michael Torrie torriem at gmail.com
Sat Mar 1 15:58:47 EST 2008


castironpi at gmail.com wrote:
> Tell Wall.  But why not [ 2, 3 ]>= 2?  Back to your question, another
> option is to not subclass.

Umm, no.  You need to actually read the posts before you respond to
them.  His question was whether or not to throw an exception in this
case.  He's *already* subclassed the type.

The first question was, should he throw an exception.  And given that
Python 3.0 will throw exceptions, he is justified in throwing exceptions
as well.  I have no idea what he would lose by throwing an exception.  I
have no idea how else he would do this.

His second question was, would his code for implementing __gt__ (and
throwing exceptions) be likely efficient.  That I cannot say.




More information about the Python-list mailing list