Why can an empty quality-check list pass an all test?
all returns true when it encounters no false item, which includes an empty iterable.
Python example and interpretation
Passing one check and executing no checks are different states. Require a nonempty manifest or an execution count when at least one test is mandatory.
checks=[]
[all(checks),bool(checks) and all(checks)]Result [True, False]
中文
为何空的质检清单也可能通过 all 检查?
all 只要没遇到假值就返回真;空可迭代对象因此也为真。
Python 算例与适用条件
有一项检查合格和根本没运行检查是两种状态。要求至少一项时,应同时核实清单非空或记录执行计数。
checks=[]
[all(checks),bool(checks) and all(checks)]结果 [True, False]