summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2019-05-27 12:45:12 (GMT)
committerGitHub <noreply@github.com>2019-05-27 12:45:12 (GMT)
commit431b540bf79f0982559b1b0e420b1b085f667bb7 (patch)
tree2e7027339ce786cc90e04cba1b03c71ecf38dfda /Lib/test/test_asyncio
parent16cefb0bc7b05c08caf08525398ff178c35dece4 (diff)
downloadcpython-431b540bf79f0982559b1b0e420b1b085f667bb7.zip
cpython-431b540bf79f0982559b1b0e420b1b085f667bb7.tar.gz
cpython-431b540bf79f0982559b1b0e420b1b085f667bb7.tar.bz2
bpo-32528: Make asyncio.CancelledError a BaseException. (GH-13528)
This will address the common mistake many asyncio users make: an "except Exception" clause breaking Tasks cancellation. In addition to this change, we stop inheriting asyncio.TimeoutError and asyncio.InvalidStateError from their concurrent.futures.* counterparts. There's no point for these exceptions to share the inheritance chain. In 3.9 we'll focus on implementing supervisors and cancel scopes, which should allow better handling of all exceptions, including SystemExit and KeyboardInterrupt
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py6
-rw-r--r--Lib/test/test_asyncio/test_tasks.py4
2 files changed, 4 insertions, 6 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index f068fc7..31018c5 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -476,7 +476,7 @@ class BaseEventLoopTests(test_utils.TestCase):
other_loop.run_until_complete, task)
def test_run_until_complete_loop_orphan_future_close_loop(self):
- class ShowStopper(BaseException):
+ class ShowStopper(SystemExit):
pass
async def foo(delay):
@@ -487,10 +487,8 @@ class BaseEventLoopTests(test_utils.TestCase):
self.loop._process_events = mock.Mock()
self.loop.call_soon(throw)
- try:
+ with self.assertRaises(ShowStopper):
self.loop.run_until_complete(foo(0.1))
- except ShowStopper:
- pass
# This call fails if run_until_complete does not clean up
# done-callback for the previous future.
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 1c1f912..114dd76 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -1527,7 +1527,7 @@ class BaseTaskTests:
async def sleeper():
await asyncio.sleep(10)
- base_exc = BaseException()
+ base_exc = SystemExit()
async def notmutch():
try:
@@ -1541,7 +1541,7 @@ class BaseTaskTests:
task.cancel()
self.assertFalse(task.done())
- self.assertRaises(BaseException, test_utils.run_briefly, loop)
+ self.assertRaises(SystemExit, test_utils.run_briefly, loop)
self.assertTrue(task.done())
self.assertFalse(task.cancelled())