Skip to content

Pre-commit snippet's mypy swap passes a path CI does not, and fails where CI passes #1188

Closed

Description

@ptr727

What

catalog/snippets/pre-commit/.pre-commit-config.yaml's type-check hook names
uvx mypy@latest . as the mypy swap. validate-task.yml's Type check Python
step
runs uv run mypy / uvx mypy@latest, with no path argument, on both
branches of its uv.lock conditional.

The trailing . is not a stylistic difference. It overrides whatever
[tool.mypy] files declares and widens the check set to the whole tree, so a repo
adopting the snippet verbatim gets a local hook that fails on a tree CI passes.

Reproduction

ptr727/Financial-Modeling at ec17a99, whose pyproject.toml declares
[tool.mypy] files = ["src"]:

$ uv run mypy              # what validate-task.yml runs
Success: no issues found in 132 source files

$ uv run mypy .            # what the snippet suggests
analysis\explore.py: error: Duplicate module named "explore" (also at ".\analysis\separation\explore.py")
Found 1 error in 1 file (errors prevented further checking)

Two explore.py files in sibling analysis/ directories are a legitimate layout
for scratch analysis scripts that files = ["src"] deliberately excludes. The
snippet drags them in and the hook refuses every commit.

Why it matters here

The snippet is the canonical shape docs/pre-commit-hooks-rollout.md tells each
Python repo to copy and adapt, and its whole purpose is to make the local gate
agree with CI. A hook that fails where CI passes is worse than no hook: it either
blocks every commit or teaches the maintainer to pass --no-verify, which then
skips the doc gates the same file exists to add.

ProjectTemplate's own tree does not hit this, so the hub's own adoption does not
exercise it.

Suggested fix

Drop the ., matching the CI invocation the snippet is mirroring:

-        name: pyright (swap for "uvx mypy@latest ." if this repo's CI runs mypy instead)
-        entry: uvx pyright@latest
+        name: pyright (swap for "uvx mypy@latest" if this repo's CI runs mypy instead)
+        entry: uvx pyright@latest

Worth a look at the pyright entry beside it for the same reason: pyright reads
[tool.pyright] include from pyproject.toml, and uvx pyright@latest with no
argument already honors it, so that half is consistent as written.

Found by

Working ptr727/Financial-Modeling through the pre-commit conversion its row in
docs/pre-commit-hooks-rollout.md still has unchecked. Filing here rather than
fixing downstream, since every Python repo on that checklist copies this snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    script

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions