diff --git a/CHANGES.rst b/CHANGES.rst index a227aec4f26..7f80c70f20c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -41,6 +41,8 @@ Bugs fixed Patch by Bénédikt Tran. * #11697: HTML Search: add 'noindex' meta robots tag. Patch by James Addison. +* #11678: Fix a possible ``ZeroDivisionError`` in ``sphinx.ext.coverage``. + Patch by Stephen Finucane. Testing ------- diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py index e3d9745e397..02096afbc29 100644 --- a/sphinx/ext/coverage.py +++ b/sphinx/ext/coverage.py @@ -290,11 +290,15 @@ def _write_py_statistics(self, op: TextIO) -> None: value = 100.0 table.append([module, '%.2f%%' % value, '%d' % len(self.py_undocumented[module])]) - table.append([ - 'TOTAL', - f'{100 * len(all_documented_objects) / len(all_objects):.2f}%', - f'{len(all_objects) - len(all_documented_objects)}', - ]) + + if all_objects: + table.append([ + 'TOTAL', + f'{100 * len(all_documented_objects) / len(all_objects):.2f}%', + f'{len(all_objects) - len(all_documented_objects)}', + ]) + else: + table.append(['TOTAL', '100', '0']) for line in _write_table(table): op.write(f'{line}\n')