Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About checking for CancelledError and its subclasses #113848

Closed
serhiy-storchaka opened this issue Jan 9, 2024 · 0 comments
Closed

About checking for CancelledError and its subclasses #113848

serhiy-storchaka opened this issue Jan 9, 2024 · 0 comments

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jan 9, 2024

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. @gvanrossum noticed 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.

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

1 participant