[Python-checkins] bpo-46995: Deprecate missing asyncio.Task.set_name() for third-party task implementations (GH-31838)

asvetlov webhook-mailer at python.org
Sun Mar 13 12:34:58 EDT 2022


https://github.com/python/cpython/commit/7e473e94a52024ac821dd2f206290423e4987ead
commit: 7e473e94a52024ac821dd2f206290423e4987ead
branch: main
author: Andrew Svetlov <andrew.svetlov at gmail.com>
committer: asvetlov <andrew.svetlov at gmail.com>
date: 2022-03-13T18:34:46+02:00
summary:

bpo-46995: Deprecate missing asyncio.Task.set_name() for third-party task implementations (GH-31838)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2022-03-12-13-50-42.bpo-46995.2kdNDg.rst
M Lib/asyncio/tasks.py
M Lib/test/test_asyncio/test_tasks.py

diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 059143fb9086f..e604298e5efc0 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -67,7 +67,10 @@ def _set_task_name(task, name):
         try:
             set_name = task.set_name
         except AttributeError:
-            pass
+            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)
 
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 950879204e703..95fabf728818b 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -12,7 +12,6 @@
 import textwrap
 import traceback
 import unittest
-import weakref
 from unittest import mock
 from types import GenericAlias
 
diff --git a/Misc/NEWS.d/next/Library/2022-03-12-13-50-42.bpo-46995.2kdNDg.rst b/Misc/NEWS.d/next/Library/2022-03-12-13-50-42.bpo-46995.2kdNDg.rst
new file mode 100644
index 0000000000000..021923f5889a7
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-03-12-13-50-42.bpo-46995.2kdNDg.rst
@@ -0,0 +1,2 @@
+Deprecate missing :meth:`asyncio.Task.set_name` for third-party task
+implementations, schedule making it mandatory in Python 3.13.



More information about the Python-checkins mailing list