[Python-Dev] Proposal - KeyboardInterrupt should inherit directly from Exception

Skip Montanaro skip@pobox.com (Skip Montanaro)
Thu, 8 Nov 2001 12:43:13 +0100


    SM> I suggest that KeyboardInterrupt should also inherit from
    SM> Exception, and not StandardError.

    BAW> It doesn't sound completely unreasonable, but I'd be -1 on it for
    BAW> Python 2.2.

Yeah, that's why I didn't ask "I know we're in feature freeze, but can we
please please please make this one itty bitty change? Please please please?
Did I forget to mention please please please?"  ;-)

    BAW> I do stuff like this all the time, although it's usually OSError.
    BAW> I love that OSError and IOError have a common base class!  I've
    BAW> often wanted all the errno's to be transformed into subclasses of
    BAW> IOError/OSError, so I could just do something like:

    BAW>     try:
    BAW>        os.mkdir(...)
    BAW>     except OSErrorEEXIST:
    BAW>        pass
    BAW>     # any other OSError propagates up

Why not make them all subclasses of OSError that are also attributes of the
OSError class.  You'd then have

    try:
       os.mkdir(...)
    except OSError.EEXIST:
       pass
    # any other OSError propagates up

which seems a little less builtin namespace polluting to me.  After all,
there are quite a few signals, yes?

Skip