Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09de8d7

Browse files
authored
pythonGH-90985: Revert "Deprecate passing a message into cancel()" (python#97999)
Reason: we were too hasty in deprecating this.We shouldn't deprecate it before we have a replacement.
1 parentc46a423 commit09de8d7

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
@@ -1144,10 +1144,8 @@ Task Object
11441144
..versionchanged::3.9
11451145
Added the *msg* parameter.
11461146

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

11521150
.. _asyncio_example_task_cancel:
11531151

‎Lib/asyncio/futures.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
importcontextvars
99
importlogging
1010
importsys
11-
importwarnings
1211
fromtypesimportGenericAlias
1312

1413
from .importbase_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-
ifmsgisnotNone:
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
ifself._state!=_PENDING:
161155
returnFalse

‎Lib/asyncio/tasks.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ def cancel(self, msg=None):
210210
211211
This also increases the task's count of cancellation requests.
212212
"""
213-
ifmsgisnotNone:
214-
warnings.warn("Passing 'msg' argument to Task.cancel() "
215-
"is deprecated since Python 3.11, and "
216-
"scheduled for removal in Python 3.14.",
217-
DeprecationWarning,stacklevel=2)
218213
self._log_traceback=False
219214
ifself.done():
220215
returnFalse

‎Lib/test/test_asyncio/test_futures.py‎

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

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

241237
deftest_future_cancel_message_setter(self):
242238
f=self._new_future(loop=self.loop)
243-
withself.assertWarnsRegex(
244-
DeprecationWarning,
245-
"Passing 'msg' argument"
246-
):
247-
f.cancel('my message')
239+
f.cancel('my message')
248240
f._cancel_message='my new message'
249241
self.assertEqual(f._cancel_message,'my new message')
250242

‎Lib/test/test_asyncio/test_tasks.py‎

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

112-
withself.assertWarnsRegex(
113-
DeprecationWarning,
114-
"Passing 'msg' argument"
115-
):
116-
t.cancel('my message')
112+
t.cancel('my message')
117113
self.assertEqual(t._cancel_message,'my message')
118114

119115
withself.assertRaises(asyncio.CancelledError)ascm:
@@ -125,11 +121,7 @@ def test_task_cancel_message_setter(self):
125121
asyncdefcoro():
126122
pass
127123
t=self.new_task(self.loop,coro())
128-
withself.assertWarnsRegex(
129-
DeprecationWarning,
130-
"Passing 'msg' argument"
131-
):
132-
t.cancel('my message')
124+
t.cancel('my message')
133125
t._cancel_message='my new message'
134126
self.assertEqual(t._cancel_message,'my new message')
135127

@@ -706,14 +698,7 @@ async def sleep():
706698
asyncdefcoro():
707699
task=self.new_task(loop,sleep())
708700
awaitasyncio.sleep(0)
709-
ifcancel_argsnotin ((), (None,)):
710-
withself.assertWarnsRegex(
711-
DeprecationWarning,
712-
"Passing 'msg' argument"
713-
):
714-
task.cancel(*cancel_args)
715-
else:
716-
task.cancel(*cancel_args)
701+
task.cancel(*cancel_args)
717702
done,pending=awaitasyncio.wait([task])
718703
task.result()
719704

@@ -747,14 +732,7 @@ async def sleep():
747732
asyncdefcoro():
748733
task=self.new_task(loop,sleep())
749734
awaitasyncio.sleep(0)
750-
ifcancel_argsnotin ((), (None,)):
751-
withself.assertWarnsRegex(
752-
DeprecationWarning,
753-
"Passing 'msg' argument"
754-
):
755-
task.cancel(*cancel_args)
756-
else:
757-
task.cancel(*cancel_args)
735+
task.cancel(*cancel_args)
758736
done,pending=awaitasyncio.wait([task])
759737
task.exception()
760738

@@ -777,17 +755,10 @@ async def sleep():
777755
fut.set_result(None)
778756
awaitasyncio.sleep(10)
779757

780-
defcancel(task,msg):
781-
withself.assertWarnsRegex(
782-
DeprecationWarning,
783-
"Passing 'msg' argument"
784-
):
785-
task.cancel(msg)
786-
787758
asyncdefcoro():
788759
inner_task=self.new_task(loop,sleep())
789760
awaitfut
790-
loop.call_soon(cancel,inner_task,'msg')
761+
loop.call_soon(inner_task.cancel,'msg')
791762
try:
792763
awaitinner_task
793764
exceptasyncio.CancelledErrorasex:
@@ -813,11 +784,7 @@ async def sleep():
813784
asyncdefcoro():
814785
task=self.new_task(loop,sleep())
815786
# We deliberately leave out the sleep here.
816-
withself.assertWarnsRegex(
817-
DeprecationWarning,
818-
"Passing 'msg' argument"
819-
):
820-
task.cancel('my message')
787+
task.cancel('my message')
821788
done,pending=awaitasyncio.wait([task])
822789
task.exception()
823790

@@ -2179,14 +2146,7 @@ async def test():
21792146
asyncdefmain():
21802147
qwe=self.new_task(loop,test())
21812148
awaitasyncio.sleep(0.2)
2182-
ifcancel_argsnotin ((), (None,)):
2183-
withself.assertWarnsRegex(
2184-
DeprecationWarning,
2185-
"Passing 'msg' argument"
2186-
):
2187-
qwe.cancel(*cancel_args)
2188-
else:
2189-
qwe.cancel(*cancel_args)
2149+
qwe.cancel(*cancel_args)
21902150
awaitqwe
21912151

21922152
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
@@ -1116,16 +1116,6 @@ static PyObject *
11161116
_asyncio_Future_cancel_impl(FutureObj*self,PyObject*msg)
11171117
/*[clinic end generated code: output=3edebbc668e5aba3 input=925eb545251f2c5a]*/
11181118
{
1119-
if (msg!=Py_None) {
1120-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
1121-
"Passing 'msg' argument to Future.cancel() "
1122-
"is deprecated since Python 3.11, and "
1123-
"scheduled for removal in Python 3.14.",
1124-
2))
1125-
{
1126-
returnNULL;
1127-
}
1128-
}
11291119
ENSURE_FUTURE_ALIVE(self)
11301120
returnfuture_cancel(self,msg);
11311121
}
@@ -2214,16 +2204,6 @@ static PyObject *
22142204
_asyncio_Task_cancel_impl(TaskObj*self,PyObject*msg)
22152205
/*[clinic end generated code: output=c66b60d41c74f9f1 input=7bb51bf25974c783]*/
22162206
{
2217-
if (msg!=Py_None) {
2218-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
2219-
"Passing 'msg' argument to Task.cancel() "
2220-
"is deprecated since Python 3.11, and "
2221-
"scheduled for removal in Python 3.14.",
2222-
2))
2223-
{
2224-
returnNULL;
2225-
}
2226-
}
22272207
self->task_log_tb=0;
22282208

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp