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?
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/