-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix return type annotation for asyncio.Task.get_coro()
#12445
Fix return type annotation for asyncio.Task.get_coro()
#12445
Conversation
This comment has been minimized.
This comment has been minimized.
This is bug in AnyIO (as in, it does not support |
Should this be made conditional on the version? The CPython docs imply that before 3.12 it could not return None. |
Oh, that's right, I'll update it. |
Issue in AnyIO opened: agronholm/anyio#764 |
I'm not sure why eager task factory can't return the coro it's passed, this seems like a cpython bug |
Diff from mypy_primer, showing the effect of this PR on open source code: anyio (https://github.com/agronholm/anyio)
+ src/anyio/_backends/_asyncio.py:335: error: Argument 1 to "getcoroutinestate" has incompatible type "Coroutine[Any, Any, Any] | None"; expected "Coroutine[Any, Any, Any]" [arg-type]
+ src/anyio/_backends/_asyncio.py:1845: error: Argument 4 to "__init__" of "TaskInfo" has incompatible type "Coroutine[Any, Any, Any] | None"; expected "Generator[Any, Any, Any] | Awaitable[Any]" [arg-type]
|
I think it's intentional, and apparently it helps performance: see here. |
It is done deliberately, it help performance as it clears cycle refs. |
It seems obvious that I suspect that performance increase was added without realising it's a breaking change, that would need a deprecation warning and 3 releases |
I merged this as it reflects the documented behavior of CPython. If you want to change CPython's behavior, open an issue on the CPython repo. |
This closes #12440.