You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
About checking for CancelledError and its subclasses #113848
For long time I wanted to replace the use of PyObject_IsInstance() with CancelledError in _asynciomodule.c. Even if the C code is correct and is closest to the corresponding Python code, it looked unnecessary complicated and bugprone. Also, PyErr_GivenExceptionMatches() is used in except implementation, so it may be more correct than an isinstance check. But I did not have tests for CancelledError subclasses which would show the difference.
Other issue. @gvanrossumnoticed that asyncio.timeout() only checks for exact CancelledError, and not its subclasses. asyncio.TaskGroup() also only checks for exact CancelledError. It is suspicious, because all other code (except _convert_future_exc() in futures.py) treats CancelledError subclasses in the same way as CancelledError. asyncio.timeout() and asyncio.TaskGroup() were added recently, so perhaps it is error in their implementation. On other hand, I do not know any use case for CancelledError subclasses.
Activity
pythongh-113848: Use PyErr_GivenExceptionMatches() for check for Canc…
pythongh-113848: Handle CancelledError subclasses in asyncio TaskGrou…
gh-113848: Use PyErr_GivenExceptionMatches() for check for CancelledE…
gh-113848: Handle CancelledError subclasses in asyncio TaskGroup() an…
pythongh-113848: Use PyErr_GivenExceptionMatches() for check for Canc…
pythongh-113848: Handle CancelledError subclasses in asyncio TaskGrou…
pythongh-113848: Use PyErr_GivenExceptionMatches() for check for Canc…
pythongh-113848: Handle CancelledError subclasses in asyncio TaskGrou…
pythongh-113848: Use PyErr_GivenExceptionMatches() for check for Canc…
pythongh-113848: Handle CancelledError subclasses in asyncio TaskGrou…
btakita commentedon May 17, 2025
Related discussion on Subclassing CancelledError...having real-world implications.