Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 67ebb39

Browse files
committed
Merge branch '3.13' of https://github.com/python/cpython into 3.13
2 parents 5f238c6 + 8f6b0af commit 67ebb39

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

Lib/concurrent/futures/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def done(self):
396396
return self._state in [CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED]
397397

398398
def __get_result(self):
399-
if self._exception:
399+
if self._exception is not None:
400400
try:
401401
raise self._exception
402402
finally:

Lib/concurrent/futures/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def process_result_item(self, result_item):
440440
work_item = self.pending_work_items.pop(result_item.work_id, None)
441441
# work_item can be None if another process terminated (see above)
442442
if work_item is not None:
443-
if result_item.exception:
443+
if result_item.exception is not None:
444444
work_item.future.set_exception(result_item.exception)
445445
else:
446446
work_item.future.set_result(result_item.result)

Lib/test/test_concurrent_futures/executor.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ def make_dummy_object(_):
2323
return MyObject()
2424

2525

26+
# Used in test_swallows_falsey_exceptions
27+
def raiser(exception, msg='std'):
28+
raise exception(msg)
29+
30+
31+
class FalseyBoolException(Exception):
32+
def __bool__(self):
33+
return False
34+
35+
36+
class FalseyLenException(Exception):
37+
def __len__(self):
38+
return 0
39+
40+
2641
class ExecutorTest:
2742
# Executor.shutdown() and context manager usage is tested by
2843
# ExecutorShutdownTest.
@@ -132,3 +147,16 @@ def test_free_reference(self):
132147
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
133148
if wr() is None:
134149
break
150+
151+
def test_swallows_falsey_exceptions(self):
152+
# see gh-132063: Prevent exceptions that evaluate as falsey
153+
# from being ignored.
154+
# Recall: `x` is falsey if `len(x)` returns 0 or `bool(x)` returns False.
155+
156+
msg = 'boolbool'
157+
with self.assertRaisesRegex(FalseyBoolException, msg):
158+
self.executor.submit(raiser, FalseyBoolException, msg).result()
159+
160+
msg = 'lenlen'
161+
with self.assertRaisesRegex(FalseyLenException, msg):
162+
self.executor.submit(raiser, FalseyLenException, msg).result()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent exceptions that evaluate as falsey (namely, when their ``__bool__`` method returns ``False`` or their ``__len__`` method returns 0)
2+
from being ignored by :class:`concurrent.futures.ProcessPoolExecutor` and :class:`concurrent.futures.ThreadPoolExecutor`.

0 commit comments

Comments
 (0)