bpo-34622: Extract asyncio exceptions into a separate module#9141
bpo-34622: Extract asyncio exceptions into a separate module#9141asvetlov merged 5 commits intopython:masterfrom
Conversation
serhiy-storchaka
left a comment
There was a problem hiding this comment.
You need to set __module__ = 'asyncio' in all classes for pickle compatibility. This is needed if you want to unpickle pickles created in 3.8 in older Python versions.
Or set fake __name__ = 'asyncio' in the asyncio.exceptions module.
I don't know whether it is a good idea to move all exceptions.
| from . import base_futures | ||
|
|
||
|
|
||
| class CancelledError(concurrent.futures.CancelledError): |
There was a problem hiding this comment.
Why define subclasses instead of just making aliases?
There was a problem hiding this comment.
The main motivation is to improve usability. There's no fundamental reason why these exceptions are derived from concurrent.future, it happened pretty much by accident. But the problem is that asyncio users see concurrent.future.TimeoutError exceptions occurring in their programs and have no idea why it's not asyncio.TimeoutError.
Moreover, we have a plan to make asyncio.CancelledError a BaseException in a follow up PR.
Lib/asyncio/futures.py
Outdated
|
|
||
|
|
||
| def _convert_future_exc(exc): | ||
| if type(exc) is concurrent.futures.CancelledError: |
|
Exception classes are not stored persistently. We are creating new exception classes anyway, no need to use tricks for very rare and weird backward compatibility use cases. A code from python < 3.8 will be unpickled into |
|
@asvetlov I agree, feel free to merge as soon as CI is green. |
https://bugs.python.org/issue34622