Fix a crash in the coverage extension when module contents are not found (#11702)

Signed-off-by: Stephen Finucane <stephen@that.guru>
Co-authored-by: Stephen Finucane <stephen@that.guru>
Authored-by: Stephen Finucane <stephen@that.guru>
This commit is contained in:
Lonami 2023-10-05 16:03:32 +02:00 committed by GitHub
parent fb1e521202
commit bb74aec2b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -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
-------

View File

@ -290,11 +290,15 @@ class CoverageBuilder(Builder):
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')