-
Notifications
You must be signed in to change notification settings - Fork 604
Description
Problem
The --ignore-regex and --exclude args in .pre-commit-config.yaml use Python list syntax (['forward', 'backward', ...]) instead of repeated CLI flags. This has two consequences:
-
--ignore-regexis compiled as a single regex. The[and]become a character class matching 20 of 26 lowercase letters (a b c d e f i k l m n o p r s t v w x y) plus uppercaseDandM. Any function or class whose name starts with one of these characters is silently skipped. This means that ~83% of the functions/methods in the repository are inadvertently ignored byinterrogate. The hook reports 100% coverage while only checking ~1,150 of ~6,500 items. -
--excludeis entirely inert. Pre-commit passes individual file paths to interrogate, which bypasses interrogate's_filter_files(only used when scanning directories). The--excludeflag has no effect regardless of its syntax.
| Configuration | Items checked | Missed | Coverage |
|---|---|---|---|
| Current hook (broken regex) | 1,148 | 0 | 100.0% |
Correctly-formed --ignore-regex |
6,078 | 847 | 86.1% |
With correct syntax, physicsnemo/ (non-experimental) has ~280 missing docstrings across ~50 files, and test/ has ~570 across ~100 files.
Fix
1. Fix the CLI syntax
Use repeated flags for --ignore-regex and move path exclusions to the pre-commit exclude pattern (the only mechanism that works when pre-commit passes individual files):
- id: interrogate
args: [
"-vv", "--ignore-init-method", "--ignore-init-module",
"--ignore-module", "--ignore-private", "--ignore-semiprivate",
"--ignore-magic", "--ignore-nested-functions", "--fail-under=99",
"--ignore-regex", "forward",
"--ignore-regex", "backward",
"--ignore-regex", "reset_parameters",
"--ignore-regex", "extra_repr",
"--ignore-regex", "MetaData",
"--ignore-regex", "apply_activation",
"--ignore-regex", "exec_activation",
"--color", "--"]
exclude: ^docs/|^physicsnemo/experimental/|^test/|^examples/2. Backfill missing docstrings in physicsnemo/
With test/ and examples/ excluded, the remaining gaps (~280 items) are in physicsnemo/. The worst files:
| File | Missed | Coverage |
|---|---|---|
nn/functional/fft.py |
14 | 52% |
nn/module/gnn_layers/distributed_graph.py |
11 | 31% |
metrics/cae/cfd.py |
6 | 45% |
nn/functional/knn/knn.py |
6 | 14% |
datapipes/healpix/couplers.py |
5 | 64% |
models/graphcast/utils/graph_backend.py |
5 | 58% |
3. Ratchet the threshold
Lower --fail-under to ~87% when fixing the syntax, then increase it as docstrings are backfilled.
**Evidence**
How --ignore-regex breaks
Interrogate's --ignore-regex is click.option(..., multiple=True). Passing the Python list as a single string means re.compile() receives the raw string ['forward', ...], where [...] is a regex character class:
>>> import re
>>> p = re.compile("['forward', 'backward', 'reset_parameters', 'extra_repr', 'MetaData', 'apply_activation','exec_activation']")
>>> bool(p.match("test_init")) # 't' in class → ignored
True
>>> bool(p.match("model")) # 'm' in class → ignored
True
>>> bool(p.match("DataLoader")) # 'D' in class → ignored
True
>>> bool(p.match("get_data")) # 'g' NOT in class → checked
FalseInterrogate calls regexp.match(node.name) in _is_ignored_common (visit.py), which is used for both _is_func_ignored and _is_class_ignored.
How --exclude breaks
When pre-commit passes individual files after --, interrogate's get_filenames_from_paths takes the os.path.isfile() branch (coverage.py), appending files directly without calling _filter_files. Confirmed empirically - adding or removing --exclude produces identical results when files are passed individually.
Reproduction
Working on main branch.
# Current hook behavior (broken regex, reports 100%):
uv run interrogate -v \
--ignore-init-method --ignore-init-module --ignore-module \
--ignore-private --ignore-semiprivate --ignore-magic \
--ignore-nested-functions --fail-under=0 \
"--ignore-regex=['forward', 'backward', 'reset_parameters', 'extra_repr', 'MetaData', 'apply_activation','exec_activation']" \
physicsnemo/ test/
# Correctly-formed regex (reports 86.1%):
uv run interrogate -v \
--ignore-init-method --ignore-init-module --ignore-module \
--ignore-private --ignore-semiprivate --ignore-magic \
--ignore-nested-functions --fail-under=0 \
--ignore-regex forward --ignore-regex backward \
--ignore-regex reset_parameters --ignore-regex extra_repr \
--ignore-regex MetaData --ignore-regex apply_activation \
--ignore-regex exec_activation \
physicsnemo/ test/Discovered during #1486, though this PR does not fix this issue.