[3.13] gh-133745: Fix asyncio task factory name/context kwarg breaks (#133948)

In 3.13.3 we accidentally broke the interface for custom task factory. Factory authors added workarounds.
This PR (for 3.13.4) unbreaks task factories that haven't made a workaround yet while also supporting those that have.

NOTE: The custom task factory API will change to what we accidentally released in 3.13.3.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
This commit is contained in:
Thomas Grainger 2025-05-18 14:50:07 +01:00 committed by GitHub
parent ebe54d7ab7
commit fd6a602d04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 18 deletions

View file

@ -1081,18 +1081,6 @@ async def throw_error():
# cancellation happens here and error is more understandable
await asyncio.sleep(0)
async def test_name(self):
name = None
async def asyncfn():
nonlocal name
name = asyncio.current_task().get_name()
async with asyncio.TaskGroup() as tg:
tg.create_task(asyncfn(), name="example name")
self.assertEqual(name, "example name")
class TestTaskGroup(BaseTestTaskGroup, unittest.IsolatedAsyncioTestCase):
loop_factory = asyncio.EventLoop