8000 GH-90985: Revert "Deprecate passing a message into cancel()" (GH-97999) · python/cpython@981b509 · GitHub
[go: up one dir, main page]

Skip to content

Commit 981b509

Browse files
miss-islingtongvanrossum
authored andcommitted
GH-90985: Revert "Deprecate passing a message into cancel()" (GH-97999)
Reason: we were too hasty in deprecating this. We shouldn't deprecate it before we have a replacement. (cherry picked from commit 09de8d7) Co-authored-by: Guido van Rossum <guido@python.org>
1 parent f008392 commit 981b509

File tree

8 files changed

+12
-102
lines changed

8 files changed

+12
-102
lines changed

Doc/library/asyncio-future.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,6 @@ Future Object
197197
.. versionchanged:: 3.9
198198
Added the *msg* parameter.
199199

200-
.. deprecated-removed:: 3.11 3.14
201-
*msg* parameter is ambiguous when multiple :meth:`cancel`
202-
are called with different cancellation messages.
203-
The argument will be removed.
204-
205200
.. method:: exception()
206201

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

283278
- :meth:`asyncio.Future.cancel` accepts an optional ``msg`` argument,
284279
but :func:`concurrent.futures.cancel` does not.
285-
286-
.. deprecated-removed:: 3.11 3.14
287-
*msg* parameter is ambiguous when multiple :meth:`cancel`
288-
are called with different cancellation messages.
289-
The argument will be removed.

Doc/library/asyncio-task.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,10 +1137,8 @@ Task Object
11371137
.. versionchanged:: 3.9
11381138
Added the *msg* parameter.
11391139

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

11451143
.. _asyncio_example_task_cancel:
11461144

Lib/asyncio/futures.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import contextvars
99
import logging
1010
import sys
11-
import warnings
1211
from types import GenericAlias
1312

1413
from . import base_futures
@@ -151,11 +150,6 @@ def cancel(self, msg=None):
151150
change the future's state to cancelled, schedule the callbacks and
152151
return True.
153152
"""
154-
if msg is not None:
155-
warnings.warn("Passing 'msg' argument to Future.cancel() "
156-
"is deprecated since Python 3.11, and "
157-
"scheduled for removal in Python 3.14.",
158-
DeprecationWarning, stacklevel=2)
159153
self.__log_traceback = False
160154
if self._state != _PENDING:
161155
return False

Lib/asyncio/tasks.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ def cancel(self, msg=None):
207207
208208
This also increases the task's count of cancellation requests.
209209
"""
210-
if msg is not None:
211-
warnings.warn("Passing 'msg' argument to Task.cancel() "
212-
"is deprecated since Python 3.11, and "
213-
"scheduled for removal in Python 3.14.",
214-
DeprecationWarning, stacklevel=2)
215210
self._log_traceback = False
216211
if self.done():
217212
return False

Lib/test/test_asyncio/test_futures.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,14 @@ def test_future_cancel_message_getter(self):
228228
self.assertTrue(hasattr(f, '_cancel_message'))
229229
self.assertEqual(f._cancel_message, None)
230230

231-
with self.assertWarnsRegex(
232-
DeprecationWarning,
233-
"Passing 'msg' argument"
234-
):
235-
f.cancel('my message')
231+
f.cancel('my message')
236232
with self.assertRaises(asyncio.CancelledError):
237233
self.loop.run_until_complete(f)
238234
self.assertEqual(f._cancel_message, 'my message')
239235

240236
def test_future_cancel_message_setter(self):
241237
f = self._new_future(loop=self.loop)
242-
with self.assertWarnsRegex(
243-
DeprecationWarning,
244-
"Passing 'msg' argument"
245-
):
246-
f.cancel('my message')
238+
f.cancel('my message')
247239
f._cancel_message = 'my new message'
248240
self.assertEqual(f._cancel_message, 'my new message')
249241

Lib/test/test_asyncio/test_tasks.py

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ async def coro():
113113
self.assertTrue(hasattr(t, '_cancel_message'))
114114
self.assertEqual(t._cancel_message, None)
115115

116-
with self.assertWarnsRegex(
117-
DeprecationWarning,
118-
"Passing 'msg' argument"
119-
):
120-
t.cancel('my message')
116+
t.cancel('my message')
121117
self.assertEqual(t._cancel_message, 'my message')
122118

123119
with self.assertRaises(asyncio.CancelledError) as cm:
@@ -129,11 +125,7 @@ def test_task_cancel_message_setter(self):
129125
async def coro():
130126
pass
131127
t = self.new_task(self.loop, coro())
132-
with self.assertWarnsRegex(
133-
DeprecationWarning,
134-
"Passing 'msg' argument"
135-
):
136-
t.cancel('my message')
128+
t.cancel('my message')
137129
t._cancel_message = 'my new message'
138130
self.assertEqual(t._cancel_message, 'my new message')
139131

@@ -710,14 +702,7 @@ async def sleep():
710702
async def coro():
711703
task = self.new_task(loop, sleep())
712704
await asyncio.sleep(0)
713-
if cancel_args not in ((), (None,)):
714-
with self.assertWarnsRegex(
715-
DeprecationWarning,
716-
"Passing 'msg' argument"
717-
):
718-
task.cancel(*cancel_args)
719-
else:
720-
task.cancel(*cancel_args)
705+
task.cancel(*cancel_args)
721706
done, pending = await asyncio.wait([task])
722707
task.result()
723708

@@ -751,14 +736,7 @@ async def sleep():
751736
async def coro():
752737
task = self.new_task(loop, sleep())
753738
await asyncio.sleep(0)
754-
if cancel_args not in ((), (None,)):
755-
with self.assertWarnsRegex(
756-
DeprecationWarning,
757-
"Passing 'msg' argument"
758-
):
759-
task.cancel(*cancel_args)
760-
else:
761-
task.cancel(*cancel_args)
739+
task.cancel(*cancel_args)
762740
done, pending = await asyncio.wait([task])
763741
task.exception()
764742

@@ -781,17 +759,10 @@ async def sleep():
781759
fut.set_result(None)
782760
await asyncio.sleep(10)
783761

784-
def cancel(task, msg):
785-
with self.assertWarnsRegex(
786-
DeprecationWarning,
787-
"Passing 'msg' argument"
788-
):
789-
task.cancel(msg)
790-
791762
async def coro():
792763
inner_task = self.new_task(loop, sleep())
793764
await fut
794-
loop.call_soon(cancel, inner_task, 'msg')
765+
loop.call_soon(inner_task.cancel, 'msg')
795766
try:
796767
await inner_task
797768
except asyncio.CancelledError as ex:
@@ -817,11 +788,7 @@ async def sleep():
817788
async def coro():
818789
task = self.new_task(loop, sleep())
819790
# We deliberately leave out the sleep here.
820-
with self.assertWarnsRegex(
821-
DeprecationWarning,
822-
"Passing 'msg' argument"
823-
):
824-
task.cancel('my message')
791+
task.cancel('my message')
825792
done, pending = await asyncio.wait([task])
826793
task.exception()
827794

@@ -2183,14 +2150,7 @@ async def test():
21832150
async def main():
21842151
qwe = self.new_task(loop, test())
21852152
await asyncio.sleep(0.2)
2186-
if cancel_args not in ((), (None,)):
2187-
with self.assertWarnsRegex(
2188-
DeprecationWarning,
2189-
"Passing 'msg' argument"
2190-
):
2191-
qwe.cancel(*cancel_args)
2192-
else:
2193-
qwe.cancel(*cancel_args)
2153+
qwe.cancel(*cancel_args)
21942154
await qwe
21952155

21962156
try:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Earlier in 3.11 we deprecated ``asyncio.Task.cancel("message")``. We realized we were too harsh, and have undeprecated it.

Modules/_asynciomodule.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,16 +1111,6 @@ static PyObject *
11111111
_asyncio_Future_cancel_impl(FutureObj *self, PyObject *msg)
11121112
/*[clinic end generated code: output=3edebbc668e5aba3 input=925eb545251f2c5a]*/
11131113
{
1114-
if (msg != Py_None) {
1115-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
1116-
"Passing 'msg' argument to Future.cancel() "
1117-
"is deprecated since Python 3.11, and "
1118-
"scheduled for removal in Python 3.14.",
1119-
2))
1120-
{
1121-
return NULL;
1122-
}
1123-
}
11241114
ENSURE_FUTURE_ALIVE(self)
11251115
return future_cancel(self, msg);
11261116
}
@@ -2201,16 +2191,6 @@ static PyObject *
22012191
_asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg)
22022192
/*[clinic end generated code: output=c66b60d41c74f9f1 input=7bb51bf25974c783]*/
22032193
{
2204-
if (msg != Py_None) {
2205-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
2206-
"Passing 'msg' argument to Task.cancel() "
2207-
"is deprecated since Python 3.11, and "
2208-
"scheduled for removal in Python 3.14.",
2209-
2))
2210-
{
2211-
return NULL;
2212-
}
2213-
}
22142194
self->task_log_tb = 0;
22152195

22162196
if (self->task_state != STATE_PENDING) {

0 commit comments

Comments
 (0)
0