MCPcopy Index your code
hub / github.com/python/cpython / scan_file_for_docs

Function scan_file_for_docs

Tools/check-c-api-docs/main.py:76–138  ·  view source on GitHub ↗

Scan a header file for C API functions.

(
    filename: str,
    text: str,
    names: set[str])

Source from the content-addressed store, hash-verified

74
75
76def scan_file_for_docs(
77 filename: str,
78 text: str,
79 names: set[str]) -> tuple[list[str], list[str]]:
80 """
81 Scan a header file for C API functions.
82 """
83 undocumented: list[str] = []
84 documented_ignored: list[str] = []
85 colors = _colorize.get_colors()
86
87 def check_for_name(name: str) -> None:
88 documented = name in names
89 if documented and (name in IGNORED):
90 documented_ignored.append(name)
91 elif not documented and (name not in IGNORED):
92 undocumented.append(name)
93
94 for function in SIMPLE_FUNCTION_REGEX.finditer(text):
95 name = function.group(2)
96 if not API_NAME_REGEX.fullmatch(name):
97 continue
98
99 check_for_name(name)
100
101 for macro in SIMPLE_MACRO_REGEX.finditer(text):
102 name = macro.group(1)
103 if not API_NAME_REGEX.fullmatch(name):
104 continue
105
106 if "(" in name:
107 name = name[: name.index("(")]
108
109 check_for_name(name)
110
111 for inline in SIMPLE_INLINE_REGEX.finditer(text):
112 name = inline.group(2)
113 if not API_NAME_REGEX.fullmatch(name):
114 continue
115
116 check_for_name(name)
117
118 for data in SIMPLE_DATA_REGEX.finditer(text):
119 name = data.group(1)
120 if not API_NAME_REGEX.fullmatch(name):
121 continue
122
123 check_for_name(name)
124
125 # Remove duplicates and sort alphabetically to keep the output deterministic
126 undocumented = list(set(undocumented))
127 undocumented.sort()
128
129 if undocumented or documented_ignored:
130 print(f"{filename} {colors.RED}BAD{colors.RESET}")
131 for name in undocumented:
132 print(f"{colors.BOLD_RED}UNDOCUMENTED:{colors.RESET} {name}")
133 for name in documented_ignored:

Callers 1

mainFunction · 0.85

Calls 6

check_for_nameFunction · 0.85
listClass · 0.85
setFunction · 0.85
groupMethod · 0.45
indexMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…