Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-90985: Revert "Deprecate passing a message into cancel()" #97999

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Doc/library/asyncio-future.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ Future Object
.. versionchanged:: 3.9
Added the *msg* parameter.

.. deprecated-removed:: 3.11 3.14
*msg* parameter is ambiguous when multiple :meth:`cancel`
are called with different cancellation messages.
The argument will be removed.

.. method:: exception()

Return the exception that was set on this Future.
Expand Down Expand Up @@ -282,8 +277,3 @@ the Future has a result::

- :meth:`asyncio.Future.cancel` accepts an optional ``msg`` argument,
but :func:`concurrent.futures.cancel` does not.

.. deprecated-removed:: 3.11 3.14
*msg* parameter is ambiguous when multiple :meth:`cancel`
are called with different cancellation messages.
The argument will be removed.
6 changes: 2 additions & 4 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1144,10 +1144,8 @@ Task Object
.. versionchanged:: 3.9
Added the *msg* parameter.

.. deprecated-removed:: 3.11 3.14
*msg* parameter is ambiguous when multiple :meth:`cancel`
are called with different cancellation messages.
The argument will be removed.
.. versionchanged:: 3.11
The ``msg`` parameter is propagated from cancelled task to its awaiter.

.. _asyncio_example_task_cancel:

Expand Down
6 changes: 0 additions & 6 deletions Lib/asyncio/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import contextvars
import logging
import sys
import warnings
from types import GenericAlias

from . import base_futures
Expand Down Expand Up @@ -151,11 +150,6 @@ def cancel(self, msg=None):
change the future's state to cancelled, schedule the callbacks and
return True.
"""
if msg is not None:
warnings.warn("Passing 'msg' argument to Future.cancel() "
"is deprecated since Python 3.11, and "
"scheduled for removal in Python 3.14.",
DeprecationWarning, stacklevel=2)
self.__log_traceback = False
if self._state != _PENDING:
return False
Expand Down
5 changes: 0 additions & 5 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,6 @@ def cancel(self, msg=None):

This also increases the task's count of cancellation requests.
"""
if msg is not None:
warnings.warn("Passing 'msg' argument to Task.cancel() "
"is deprecated since Python 3.11, and "
"scheduled for removal in Python 3.14.",
DeprecationWarning, stacklevel=2)
self._log_traceback = False
if self.done():
return False
Expand Down
12 changes: 2 additions & 10 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,14 @@ def test_future_cancel_message_getter(self):
self.assertTrue(hasattr(f, '_cancel_message'))
self.assertEqual(f._cancel_message, None)

with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
f.cancel('my message')
f.cancel('my message')
with self.assertRaises(asyncio.CancelledError):
self.loop.run_until_complete(f)
self.assertEqual(f._cancel_message, 'my message')

def test_future_cancel_message_setter(self):
f = self._new_future(loop=self.loop)
with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
f.cancel('my message')
f.cancel('my message')
f._cancel_message = 'my new message'
self.assertEqual(f._cancel_message, 'my new message')

Expand Down
54 changes: 7 additions & 47 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ async def coro():
self.assertTrue(hasattr(t, '_cancel_message'))
self.assertEqual(t._cancel_message, None)

with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
t.cancel('my message')
t.cancel('my message')
self.assertEqual(t._cancel_message, 'my message')

with self.assertRaises(asyncio.CancelledError) as cm:
Expand All @@ -125,11 +121,7 @@ def test_task_cancel_message_setter(self):
async def coro():
pass
t = self.new_task(self.loop, coro())
with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
t.cancel('my message')
t.cancel('my message')
t._cancel_message = 'my new message'
self.assertEqual(t._cancel_message, 'my new message')

Expand Down Expand Up @@ -706,14 +698,7 @@ async def sleep():
async def coro():
task = self.new_task(loop, sleep())
await asyncio.sleep(0)
if cancel_args not in ((), (None,)):
with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
task.cancel(*cancel_args)
else:
task.cancel(*cancel_args)
task.cancel(*cancel_args)
done, pending = await asyncio.wait([task])
task.result()

Expand Down Expand Up @@ -747,14 +732,7 @@ async def sleep():
async def coro():
task = self.new_task(loop, sleep())
await asyncio.sleep(0)
if cancel_args not in ((), (None,)):
with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
task.cancel(*cancel_args)
else:
task.cancel(*cancel_args)
task.cancel(*cancel_args)
done, pending = await asyncio.wait([task])
task.exception()

Expand All @@ -777,17 +755,10 @@ async def sleep():
fut.set_result(None)
await asyncio.sleep(10)

def cancel(task, msg):
with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
task.cancel(msg)

async def coro():
inner_task = self.new_task(loop, sleep())
await fut
loop.call_soon(cancel, inner_task, 'msg')
loop.call_soon(inner_task.cancel, 'msg')
try:
await inner_task
except asyncio.CancelledError as ex:
Expand All @@ -813,11 +784,7 @@ async def sleep():
async def coro():
task = self.new_task(loop, sleep())
# We deliberately leave out the sleep here.
with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
task.cancel('my message')
task.cancel('my message')
done, pending = await asyncio.wait([task])
task.exception()

Expand Down Expand Up @@ -2179,14 +2146,7 @@ async def test():
async def main():
qwe = self.new_task(loop, test())
await asyncio.sleep(0.2)
if cancel_args not in ((), (None,)):
with self.assertWarnsRegex(
DeprecationWarning,
"Passing 'msg' argument"
):
qwe.cancel(*cancel_args)
else:
qwe.cancel(*cancel_args)
qwe.cancel(*cancel_args)
await qwe

try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Earlier in 3.11 we deprecated ``asyncio.Task.cancel("message")``. We realized we were too harsh, and have undeprecated it.
20 changes: 0 additions & 20 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,16 +1116,6 @@ static PyObject *
_asyncio_Future_cancel_impl(FutureObj *self, PyObject *msg)
/*[clinic end generated code: output=3edebbc668e5aba3 input=925eb545251f2c5a]*/
{
if (msg != Py_None) {
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"Passing 'msg' argument to Future.cancel() "
"is deprecated since Python 3.11, and "
"scheduled for removal in Python 3.14.",
2))
{
return NULL;
}
}
ENSURE_FUTURE_ALIVE(self)
return future_cancel(self, msg);
}
Expand Down Expand Up @@ -2214,16 +2204,6 @@ static PyObject *
_asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg)
/*[clinic end generated code: output=c66b60d41c74f9f1 input=7bb51bf25974c783]*/
{
if (msg != Py_None) {
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"Passing 'msg' argument to Task.cancel() "
"is deprecated since Python 3.11, and "
"scheduled for removal in Python 3.14.",
2))
{
return NULL;
}
}
self->task_log_tb = 0;

if (self->task_state != STATE_PENDING) {
Expand Down