MCPcopy Index your code
hub / github.com/numpy/numpy / scan_file

Function scan_file

tools/ci/check_c_api_usage.py:87–118  ·  view source on GitHub ↗

Scan a single file. Returns list of (func_name, line_number, path_str, raw_line_str).

(
        path: Path,
        func_rx: Pattern[str],
        noqa_markers: tuple[str, ...]
        )

Source from the content-addressed store, hash-verified

85 return re.compile(r"(?<!\w)(?:" + "|".join(map(re.escape, funcs)) + r")(?!\w)")
86
87def scan_file(
88 path: Path,
89 func_rx: Pattern[str],
90 noqa_markers: tuple[str, ...]
91 ) -> list[tuple[str, int, str, str]]:
92 """
93 Scan a single file.
94 Returns list of (func_name, line_number, path_str, raw_line_str).
95 """
96 hits: list[tuple[str, int, str, str]] = []
97 in_block = False
98 noqa_set = set(noqa_markers)
99
100 try:
101 with path.open("r", encoding="utf-8", errors="ignore") as f:
102 for lineno, raw in enumerate(f, 1):
103 # Skip if approved by noqa markers
104 if any(mark in raw for mark in noqa_set):
105 continue
106
107 # Remove comments; if nothing remains, skip
108 code, in_block = strip_comments(raw.rstrip("\n"), in_block)
109 if not code.strip():
110 continue
111
112 # Find all suspicious calls in non-comment code
113 for m in func_rx.finditer(code):
114 hits.append((m.group(0), lineno, str(path), raw.rstrip("\n")))
115 except FileNotFoundError:
116 # File may have disappeared; ignore gracefully
117 pass
118 return hits
119
120
121def main(argv: list[str] | None = None) -> int:

Callers 1

mainFunction · 0.85

Calls 5

anyFunction · 0.85
strip_commentsFunction · 0.85
rstripMethod · 0.80
stripMethod · 0.80
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…