File tree Expand file tree Collapse file tree 2 files changed +58
-1
lines changed Expand file tree Collapse file tree 2 files changed +58
-1
lines changed Original file line number Diff line number Diff line change 4444def assertRaises (typ : type , msg : str = '' ) -> Iterator [None ]:
4545 try :
4646 yield
47- except Exception as e :
47+ except BaseException as e :
4848 assert type (e ) is typ , f"{ e !r} is not a { typ .__name__ } "
4949 assert msg in str (e ), f'Message "{ e } " does not match "{ msg } "'
5050 else :
Original file line number Diff line number Diff line change @@ -1234,3 +1234,60 @@ def test_callable_arg_same_name_as_helper() -> None:
12341234
12351235[file asyncio/__init__.pyi]
12361236def run(x: object) -> object: ...
1237+
1238+ [case testRunAsyncCancelFinallySpecialCase]
1239+ import asyncio
1240+
1241+ from testutil import assertRaises
1242+
1243+ # Greatly simplified from asyncio.Condition
1244+ class Condition:
1245+ async def acquire(self) -> None: pass
1246+
1247+ async def wait(self) -> bool:
1248+ l = asyncio.get_running_loop()
1249+ fut = l.create_future()
1250+ a = []
1251+ try:
1252+ try:
1253+ a.append(fut)
1254+ try:
1255+ await fut
1256+ return True
1257+ finally:
1258+ a.pop()
1259+ finally:
1260+ err = None
1261+ while True:
1262+ try:
1263+ await self.acquire()
1264+ break
1265+ except asyncio.CancelledError as e:
1266+ err = e
1267+
1268+ if err is not None:
1269+ try:
1270+ raise err
1271+ finally:
1272+ err = None
1273+ except BaseException:
1274+ raise
1275+
1276+ async def do_cancel() -> None:
1277+ cond = Condition()
1278+ wait = asyncio.create_task(cond.wait())
1279+ asyncio.get_running_loop().call_soon(wait.cancel)
1280+ with assertRaises(asyncio.CancelledError):
1281+ await wait
1282+
1283+ def test_cancel_special_case() -> None:
1284+ asyncio.run(do_cancel())
1285+
1286+ [file asyncio/__init__.pyi]
1287+ from typing import Any
1288+
1289+ class CancelledError(Exception): ...
1290+
1291+ def run(x: object) -> object: ...
1292+ def get_running_loop() -> Any: ...
1293+ def create_task(x: object) -> Any: ...
You can’t perform that action at this time.
0 commit comments