(argv: list[str] | None = None)
| 119 | |
| 120 | |
| 121 | def main(argv: list[str] | None = None) -> int: |
| 122 | # List of suspicious function calls: |
| 123 | suspicious_funcs: tuple[str, ...] = ( |
| 124 | "PyList_GetItem", |
| 125 | "PyDict_GetItem", |
| 126 | "PyDict_GetItemWithError", |
| 127 | "PyDict_GetItemString", |
| 128 | "PyDict_SetDefault", |
| 129 | "PyDict_Next", |
| 130 | "PyWeakref_GetObject", |
| 131 | "PyWeakref_GET_OBJECT", |
| 132 | "PyList_GET_ITEM", |
| 133 | "_PyDict_GetItemStringWithError", |
| 134 | "PySequence_Fast" |
| 135 | ) |
| 136 | func_rx = build_func_rx(suspicious_funcs) |
| 137 | noqa_markers = ( |
| 138 | "noqa: borrowed-ref OK", |
| 139 | "noqa: borrowed-ref - manual fix needed" |
| 140 | ) |
| 141 | default_exts = {".c", ".h", ".c.src", ".cpp"} |
| 142 | default_excludes = {"pythoncapi-compat"} |
| 143 | |
| 144 | ap = argparse.ArgumentParser(description="Borrow-ref C API linter (Python).") |
| 145 | ap.add_argument( |
| 146 | "--quiet", |
| 147 | action="store_true", |
| 148 | help="Suppress normal output; exit status alone indicates result (useful\ |
| 149 | for CI).", |
| 150 | ) |
| 151 | ap.add_argument( |
| 152 | "-j", "--jobs", |
| 153 | type=int, |
| 154 | default=0, |
| 155 | help="Number of worker threads (0=auto, 1=sequential).", |
| 156 | ) |
| 157 | ap.add_argument( |
| 158 | "--root", |
| 159 | default="numpy", |
| 160 | type=str, |
| 161 | help="Root directory to scan (default: numpy)" |
| 162 | ) |
| 163 | ap.add_argument( |
| 164 | "--ext", |
| 165 | action="append", |
| 166 | default=None, |
| 167 | help=f"File extension(s) to include (repeatable). Defaults to {default_exts}", |
| 168 | ) |
| 169 | ap.add_argument( |
| 170 | "--exclude", |
| 171 | action="append", |
| 172 | default=None, |
| 173 | help=f"Directory name(s) to exclude (repeatable). Default: {default_excludes}", |
| 174 | ) |
| 175 | args = ap.parse_args(argv) |
| 176 | |
| 177 | if args.ext: |
| 178 | exts = {e if e.startswith(".") else f".{e}" for e in args.ext} |
no test coverage detected
searching dependent graphs…