Skip to content

Commit

Permalink
Fix a crash in the coverage extension when module contents are not fo…
Browse files Browse the repository at this point in the history
…und (#11702)

Signed-off-by: Stephen Finucane <[email protected]>
Co-authored-by: Stephen Finucane <[email protected]>
Authored-by: Stephen Finucane <[email protected]>
  • Loading branch information
Lonami and stephenfin authored Oct 5, 2023
1 parent fb1e521 commit bb74aec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
14 changes: 9 additions & 5 deletions sphinx/ext/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit bb74aec

Please sign in to comment.