]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-105684: Require `asyncio.Task` implementations to support `set_name` method (...
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Tue, 13 Jun 2023 06:06:40 +0000 (11:36 +0530)
committerGitHub <noreply@github.com>
Tue, 13 Jun 2023 06:06:40 +0000 (06:06 +0000)
Lib/asyncio/base_events.py
Lib/asyncio/taskgroups.py
Lib/asyncio/tasks.py
Lib/test/test_asyncio/test_runners.py
Misc/NEWS.d/next/Library/2023-06-12-10-40-38.gh-issue-105684.yiHkFD.rst [new file with mode: 0644]

index 32d7e1c481ecc55018e091de6126e9590dcaa72f..f650e6b0488cf8ce0ced1a0fa076758d966dea49 100644 (file)
@@ -443,7 +443,7 @@ class BaseEventLoop(events.AbstractEventLoop):
             else:
                 task = self._task_factory(self, coro, context=context)
 
-            tasks._set_task_name(task, name)
+            task.set_name(name)
 
         return task
 
index 06b2e0db86a1fe59010132e5339204da0dbf3d9d..bf92bbaf0d005826f76351b115d53cc051c375d6 100644 (file)
@@ -163,7 +163,7 @@ class TaskGroup:
             task = self._loop.create_task(coro)
         else:
             task = self._loop.create_task(coro, context=context)
-        tasks._set_task_name(task, name)
+        task.set_name(name)
         # optimization: Immediately call the done callback if the task is
         # already done (e.g. if the coro was able to complete eagerly),
         # and skip scheduling a done callback
index 4250bb0753879a91137ab90bc855ef68a9547ede..75dd3cb6c2e9874d847a1c650085be3e3030b610 100644 (file)
@@ -68,19 +68,6 @@ def all_tasks(loop=None):
             if futures._get_loop(t) is loop and not t.done()}
 
 
-def _set_task_name(task, name):
-    if name is not None:
-        try:
-            set_name = task.set_name
-        except AttributeError:
-            warnings.warn("Task.set_name() was added in Python 3.8, "
-                      "the method support will be mandatory for third-party "
-                      "task implementations since 3.13.",
-                      DeprecationWarning, stacklevel=3)
-        else:
-            set_name(name)
-
-
 class Task(futures._PyFuture):  # Inherit Python Task implementation
                                 # from a Python Future implementation.
 
@@ -412,7 +399,7 @@ def create_task(coro, *, name=None, context=None):
     else:
         task = loop.create_task(coro, context=context)
 
-    _set_task_name(task, name)
+    task.set_name(name)
     return task
 
 
index 811cf8b72488b8ca113320e2b1e9f12e08139c41..b1eb6f492886b35e929c781ec9b26615cef75b03 100644 (file)
@@ -243,6 +243,8 @@ class RunTests(BaseTest):
             def get_loop(self, *args, **kwargs):
                 return self._task.get_loop(*args, **kwargs)
 
+            def set_name(self, *args, **kwargs):
+                return self._task.set_name(*args, **kwargs)
 
         async def main():
             interrupt_self()
diff --git a/Misc/NEWS.d/next/Library/2023-06-12-10-40-38.gh-issue-105684.yiHkFD.rst b/Misc/NEWS.d/next/Library/2023-06-12-10-40-38.gh-issue-105684.yiHkFD.rst
new file mode 100644 (file)
index 0000000..b0d4eb3
--- /dev/null
@@ -0,0 +1,3 @@
+Supporting :meth:`asyncio.Task.set_name` is now mandatory for third party task implementations.
+The undocumented :func:`!_set_task_name` function (deprecated since 3.8) has been removed.
+Patch by Kumar Aditya.