[Python-ideas] Introduce BaseTimeoutError

Ram Rachum ram at rachum.com
Sat Apr 1 15:27:34 EDT 2017


Today I got burned because I had code that did this:

    except TimeoutError:

When it should have done this:

    except socket.timeout:

There's also another timeout error class in asyncio.

Initially I thought, why not make them all use the same exception class?
But Guido objects to that:

I considered this, and decided against unifying the two TimeoutErrors.

First the builtin TimeoutError is specifically a subclass of OSError
representing the case where errno is ETIMEDOUT.  But
asyncio.TimeoutError means nothing of the sort.

Second, the precedent is concurrent.futures.TimeoutError. The asyncio
one is used under the same conditions as that one.

I think we should just update the links in the docs to be correct.

So here's my idea: Define a new base class `BaseTimeoutError` and have it
be a base class of all other timeout errors. This way people could do:

    except BaseTimeoutError:

And it'll catch all of them.

I thought of doing it myself as an abc, but if I remember correctly the
except logic ignored __subclasshook__ or __instancecheck__ or whatever is
used by abc, so I think this can only work by modifying CPython.


What do you think?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170401/96c0dce9/attachment.html>


More information about the Python-ideas mailing list