Skip to content

Commit 2510476

Browse files
committed
Eliminate some duplication.
1 parent ec03845 commit 2510476

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Tools/check-c-api-docs/main.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"""
1515

1616
FOUND_UNDOCUMENTED = f"""\
17-
Found some undocumented C API!
17+
Found some undocumented C API(s)!
1818
19-
Python requires documentation on all public C API functions.
19+
Python requires documentation on all public C API symbols, macros, and types.
2020
If these API(s) were not meant to be public, please prefix them with a
2121
leading underscore (_PySomething_API) or move them to the internal C API
2222
(pycore_*.h files).
@@ -144,20 +144,19 @@ def main() -> None:
144144
all_missing += missing
145145

146146
fail = False
147-
if all_missing != []:
148-
s = "s" if len(all_missing) != 1 else ""
149-
print(f"-- {len(all_missing)} missing C API{s} --")
150-
for name in all_missing:
151-
print(f" - {name}")
152-
print(FOUND_UNDOCUMENTED)
153-
fail = True
147+
to_check = [
148+
(all_missing, "missing", FOUND_UNDOCUMENTED),
149+
(all_found_ignored, "documented but ignored", FOUND_IGNORED_DOCUMENTED),
150+
]
151+
for name_list, what, message in to_check:
152+
if not name_list:
153+
continue
154154

155-
if all_found_ignored != []:
156-
s = "s" if len(all_found_ignored) != 1 else ""
157-
print(f"-- Found {len(all_found_ignored)} documented but ignored C API{s} --")
158-
for name in all_found_ignored:
155+
s = "s" if len(name_list) != 1 else ""
156+
print(f"-- {len(name_list)} {what} C API{s} --")
157+
for name in all_missing:
159158
print(f" - {name}")
160-
print(FOUND_IGNORED_DOCUMENTED)
159+
print(message)
161160
fail = True
162161

163162
sys.exit(1 if fail else 0)

0 commit comments

Comments
 (0)