Skip to content

Commit 7c2f6d5

Browse files
committed
Compensate for asyncio changes in Python 3.13.3/3.14
In python/cpython@38a9956 (backported to 3.13 as python/cpython@7b0543e), Python moved the responsibility for setting the task name from `asyncio.create_task` to the `Task` constructor. While `uvloop` itself is unaffected, this causes `test_set_task_name` to fail when run with `asyncio`. Compensate for that in this particular test. It's possible that `uvloop`'s behaviour should be changed to match `asyncio`'s depending on the Python version, but that seems like a more involved change. For now, this at least gets the tests passing again. Most of this analysis and patch were from Martin Hostettler in https://bugs.debian.org/1101258#24; I just tweaked the patch slightly to ensure it still passes on older Python versions.
1 parent 7bb12a1 commit 7c2f6d5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tests/test_base.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,14 @@ def get_name(self):
576576
async def coro():
577577
pass
578578

579-
factory = lambda loop, coro, **kwargs: MyTask(
580-
coro, loop=loop, **kwargs
581-
)
579+
def factory(loop, coro, **kwargs):
580+
task = MyTask(coro, loop=loop, **kwargs)
581+
# Python moved the responsibility to set the name to the Task
582+
# class constructor, so MyTask.set_name is never called by
583+
# Python's create_task. Compensate for that here.
584+
if self.is_asyncio_loop() and "name" in kwargs:
585+
task.set_name(kwargs["name"])
586+
return task
582587

583588
self.assertIsNone(self.loop.get_task_factory())
584589
task = self.loop.create_task(coro(), name="mytask")

0 commit comments

Comments
 (0)