Skip to content

Conversation

@ZeroIntensity
Copy link
Member

This closes #12440.

@github-actions

This comment has been minimized.

@ZeroIntensity
Copy link
Member Author

This is bug in AnyIO (as in, it does not support eager_task_factory), as found when debugging this issue report.

@JelleZijlstra
Copy link
Member

Should this be made conditional on the version? The CPython docs imply that before 3.12 it could not return None.

@ZeroIntensity
Copy link
Member Author

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.

@ZeroIntensity
Copy link
Member Author

Issue in AnyIO opened: agronholm/anyio#764

@graingert
Copy link
Contributor

I'm not sure why eager task factory can't return the coro it's passed, this seems like a cpython bug

@github-actions
Copy link
Contributor

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]

@ZeroIntensity
Copy link
Member Author

I think it's intentional, and apparently it helps performance: see here.

@kumaraditya303
Copy link
Contributor

It is done deliberately, it help performance as it clears cycle refs.

@graingert
Copy link
Contributor

It seems obvious that asyncio.eager_task_factory(loop, coro).get_coro() can return the coro without being a breaking change.

I suspect that performance increase was added without realising it's a breaking change, that would need a deprecation warning and 3 releases

@JelleZijlstra JelleZijlstra merged commit d2ccc9a into python:main Jul 27, 2024
@JelleZijlstra
Copy link
Member

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.

max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio.Task.get_coro can return None on 3.12+

4 participants