Skip to content

🐛[BUG]: interrogate setup uses broken syntax for --ignore-regex and --exclude, masking ~850 missing doctstrings #1485

@peterdsharpe

Description

@peterdsharpe

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:

  1. --ignore-regex is 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 uppercase D and M. 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 by interrogate. The hook reports 100% coverage while only checking ~1,150 of ~6,500 items.

  2. --exclude is entirely inert. Pre-commit passes individual file paths to interrogate, which bypasses interrogate's _filter_files (only used when scanning directories). The --exclude flag 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
False

Interrogate 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ? - Needs TriageNeed team to review and classifybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions