Skip to content

Commit ef7e7f6

Browse files
authored
Merge branch 'main' into unittest-async-case-event-loop-setup
2 parents 1194f25 + da0aa51 commit ef7e7f6

5 files changed

Lines changed: 40 additions & 31 deletions

File tree

‎Doc/library/errno.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,6 @@ defined by the module. The specific list of defined symbols is available as
663663
Capabilities insufficient. This error is mapped to the exception
664664
:exc:`PermissionError`.
665665

666-
.. availability:: WASI
666+
.. availability:: WASI, FreeBSD
667667

668668
.. versionadded:: 3.11.1

‎Lib/asyncio/taskgroups.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ async def __aexit__(self, et, exc, tb):
116116
if self._base_error is not None:
117117
raise self._base_error
118118

119-
if propagate_cancellation_error is not None:
120-
# The wrapping task was cancelled; since we're done with
121-
# closing all child tasks, just propagate the cancellation
122-
# request now.
119+
# Propagate CancelledError if there is one, except if there
120+
# are other errors -- those have priority.
121+
if propagate_cancellation_error and not self._errors:
123122
raise propagate_cancellation_error
124123

125124
if et is not None and et is not exceptions.CancelledError:

‎Lib/test/test_asyncio/test_taskgroups.py‎

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -230,29 +230,29 @@ async def runner():
230230

231231
self.assertEqual(NUM, 15)
232232

233-
async def test_cancellation_in_body(self):
233+
async def test_taskgroup_08(self):
234234

235235
async def foo():
236-
await asyncio.sleep(0.1)
237-
1 / 0
236+
try:
237+
await asyncio.sleep(10)
238+
finally:
239+
1 / 0
238240

239241
async def runner():
240242
async with taskgroups.TaskGroup() as g:
241243
for _ in range(5):
242244
g.create_task(foo())
243245

244-
try:
245-
await asyncio.sleep(10)
246-
except asyncio.CancelledError:
247-
raise
246+
await asyncio.sleep(10)
248247

249248
r = asyncio.create_task(runner())
250249
await asyncio.sleep(0.1)
251250

252251
self.assertFalse(r.done())
253252
r.cancel()
254-
with self.assertRaises(asyncio.CancelledError) as cm:
253+
with self.assertRaises(ExceptionGroup) as cm:
255254
await r
255+
self.assertEqual(get_error_types(cm.exception), {ZeroDivisionError})
256256

257257
async def test_taskgroup_09(self):
258258

@@ -316,33 +316,37 @@ async def runner():
316316
async def test_taskgroup_11(self):
317317

318318
async def foo():
319-
await asyncio.sleep(0.1)
320-
1 / 0
319+
try:
320+
await asyncio.sleep(10)
321+
finally:
322+
1 / 0
321323

322324
async def runner():
323325
async with taskgroups.TaskGroup():
324326
async with taskgroups.TaskGroup() as g2:
325327
for _ in range(5):
326328
g2.create_task(foo())
327329

328-
try:
329-
await asyncio.sleep(10)
330-
except asyncio.CancelledError:
331-
raise
330+
await asyncio.sleep(10)
332331

333332
r = asyncio.create_task(runner())
334333
await asyncio.sleep(0.1)
335334

336335
self.assertFalse(r.done())
337336
r.cancel()
338-
with self.assertRaises(asyncio.CancelledError):
337+
with self.assertRaises(ExceptionGroup) as cm:
339338
await r
340339

340+
self.assertEqual(get_error_types(cm.exception), {ExceptionGroup})
341+
self.assertEqual(get_error_types(cm.exception.exceptions[0]), {ZeroDivisionError})
342+
341343
async def test_taskgroup_12(self):
342344

343345
async def foo():
344-
await asyncio.sleep(0.1)
345-
1 / 0
346+
try:
347+
await asyncio.sleep(10)
348+
finally:
349+
1 / 0
346350

347351
async def runner():
348352
async with taskgroups.TaskGroup() as g1:
@@ -352,19 +356,19 @@ async def runner():
352356
for _ in range(5):
353357
g2.create_task(foo())
354358

355-
try:
356-
await asyncio.sleep(10)
357-
except asyncio.CancelledError:
358-
raise
359+
await asyncio.sleep(10)
359360

360361
r = asyncio.create_task(runner())
361362
await asyncio.sleep(0.1)
362363

363364
self.assertFalse(r.done())
364365
r.cancel()
365-
with self.assertRaises(asyncio.CancelledError):
366+
with self.assertRaises(ExceptionGroup) as cm:
366367
await r
367368

369+
self.assertEqual(get_error_types(cm.exception), {ExceptionGroup})
370+
self.assertEqual(get_error_types(cm.exception.exceptions[0]), {ZeroDivisionError})
371+
368372
async def test_taskgroup_13(self):
369373

370374
async def crash_after(t):
@@ -424,8 +428,9 @@ async def runner():
424428

425429
self.assertFalse(r.done())
426430
r.cancel()
427-
with self.assertRaises(asyncio.CancelledError):
431+
with self.assertRaises(ExceptionGroup) as cm:
428432
await r
433+
self.assertEqual(get_error_types(cm.exception), {ZeroDivisionError})
429434

430435
async def test_taskgroup_16(self):
431436

@@ -451,8 +456,9 @@ async def runner():
451456

452457
self.assertFalse(r.done())
453458
r.cancel()
454-
with self.assertRaises(asyncio.CancelledError):
459+
with self.assertRaises(ExceptionGroup) as cm:
455460
await r
461+
self.assertEqual(get_error_types(cm.exception), {ZeroDivisionError})
456462

457463
async def test_taskgroup_17(self):
458464
NUM = 0

‎Lib/test/test_exception_hierarchy.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_select_error(self):
6363
+-- InterruptedError EINTR
6464
+-- IsADirectoryError EISDIR
6565
+-- NotADirectoryError ENOTDIR
66-
+-- PermissionError EACCES, EPERM
66+
+-- PermissionError EACCES, EPERM, ENOTCAPABLE
6767
+-- ProcessLookupError ESRCH
6868
+-- TimeoutError ETIMEDOUT
6969
"""
@@ -75,6 +75,8 @@ def _make_map(s):
7575
continue
7676
excname, _, errnames = line.partition(' ')
7777
for errname in filter(None, errnames.strip().split(', ')):
78+
if errname == "ENOTCAPABLE" and not hasattr(errno, errname):
79+
continue
7880
_map[getattr(errno, errname)] = getattr(builtins, excname)
7981
return _map
8082
_map = _make_map(_pep_map)
@@ -91,7 +93,7 @@ def test_errno_mapping(self):
9193
othercodes = set(errno.errorcode) - set(self._map)
9294
for errcode in othercodes:
9395
e = OSError(errcode, "Some message")
94-
self.assertIs(type(e), OSError)
96+
self.assertIs(type(e), OSError, repr(e))
9597

9698
def test_try_except(self):
9799
filename = "some_hopefully_non_existing_file"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
When a task catches :exc:`asyncio.CancelledError` and raises some other error,
2+
the other error should generally not silently be suppressed.

0 commit comments

Comments
 (0)