[Python-checkins] Add asyncio.Handle.cancelled() method (#2388)

Andrew Svetlov webhook-mailer at python.org
Tue Nov 7 04:06:11 EST 2017


https://github.com/python/cpython/commit/69cfed1cd7be968fa4f6c69eb6dccc94bce5d45c
commit: 69cfed1cd7be968fa4f6c69eb6dccc94bce5d45c
branch: master
author: Marat Sharafutdinov <decaz89 at gmail.com>
committer: Andrew Svetlov <andrew.svetlov at gmail.com>
date: 2017年11月07日T12:06:05+03:00
summary:
Add asyncio.Handle.cancelled() method (#2388)
files:
A Misc/NEWS.d/next/Library/2017-11-04-19-28-08.bpo-31943.bxw5gM.rst
M Doc/library/asyncio-eventloop.rst
M Lib/asyncio/events.py
M Lib/test/test_asyncio/test_events.py
diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst
index 9bc7a40fc71..e635cba659a 100644
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -867,6 +867,12 @@ Handle
 Cancel the call. If the callback is already canceled or executed,
 this method has no effect.
 
+ .. method:: cancelled()
+
+ Return ``True`` if the call was cancelled.
+
+ .. versionadded:: 3.7
+
 
 Event loop examples
 -------------------
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index c2663c5062d..270a5e4c33d 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -117,6 +117,9 @@ def cancel(self):
 self._callback = None
 self._args = None
 
+ def cancelled(self):
+ return self._cancelled
+
 def _run(self):
 try:
 self._callback(*self._args)
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 0ea9c086747..5394ddfce24 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2305,10 +2305,10 @@ def callback(*args):
 h = asyncio.Handle(callback, args, self.loop)
 self.assertIs(h._callback, callback)
 self.assertIs(h._args, args)
- self.assertFalse(h._cancelled)
+ self.assertFalse(h.cancelled())
 
 h.cancel()
- self.assertTrue(h._cancelled)
+ self.assertTrue(h.cancelled())
 
 def test_callback_with_exception(self):
 def callback():
@@ -2494,11 +2494,11 @@ def callback(*args):
 h = asyncio.TimerHandle(when, callback, args, mock.Mock())
 self.assertIs(h._callback, callback)
 self.assertIs(h._args, args)
- self.assertFalse(h._cancelled)
+ self.assertFalse(h.cancelled())
 
 # cancel
 h.cancel()
- self.assertTrue(h._cancelled)
+ self.assertTrue(h.cancelled())
 self.assertIsNone(h._callback)
 self.assertIsNone(h._args)
 
diff --git a/Misc/NEWS.d/next/Library/2017-11-04-19-28-08.bpo-31943.bxw5gM.rst b/Misc/NEWS.d/next/Library/2017-11-04-19-28-08.bpo-31943.bxw5gM.rst
new file mode 100644
index 00000000000..a26aca37b5f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-11-04-19-28-08.bpo-31943.bxw5gM.rst
@@ -0,0 +1 @@
+Add a ``cancelled()`` method to :class:`asyncio.Handle`. Patch by Marat Sharafutdinov.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /