Skip to content

Commit bb74aec

Browse files
Lonamistephenfin
andauthored
Fix a crash in the coverage extension when module contents are not found (#11702)
Signed-off-by: Stephen Finucane <[email protected]> Co-authored-by: Stephen Finucane <[email protected]> Authored-by: Stephen Finucane <[email protected]>
1 parent fb1e521 commit bb74aec

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Bugs fixed
4141
Patch by Bénédikt Tran.
4242
* #11697: HTML Search: add 'noindex' meta robots tag.
4343
Patch by James Addison.
44+
* #11678: Fix a possible ``ZeroDivisionError`` in ``sphinx.ext.coverage``.
45+
Patch by Stephen Finucane.
4446

4547
Testing
4648
-------

sphinx/ext/coverage.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,15 @@ def _write_py_statistics(self, op: TextIO) -> None:
290290
value = 100.0
291291

292292
table.append([module, '%.2f%%' % value, '%d' % len(self.py_undocumented[module])])
293-
table.append([
294-
'TOTAL',
295-
f'{100 * len(all_documented_objects) / len(all_objects):.2f}%',
296-
f'{len(all_objects) - len(all_documented_objects)}',
297-
])
293+
294+
if all_objects:
295+
table.append([
296+
'TOTAL',
297+
f'{100 * len(all_documented_objects) / len(all_objects):.2f}%',
298+
f'{len(all_objects) - len(all_documented_objects)}',
299+
])
300+
else:
301+
table.append(['TOTAL', '100', '0'])
298302

299303
for line in _write_table(table):
300304
op.write(f'{line}\n')

0 commit comments

Comments
 (0)