Skip to content

ci: add mypy to pre-commit hooks#738

Merged
knoepfel merged 2 commits into
mainfrom
maintenance/pre-commit-mypy-hook
Jul 24, 2026
Merged

ci: add mypy to pre-commit hooks#738
knoepfel merged 2 commits into
mainfrom
maintenance/pre-commit-mypy-hook

Conversation

@greenc-FNAL

@greenc-FNAL greenc-FNAL commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Add the mypy static type checker to the pre-commit configuration to
improve Python type safety and catch potential bugs before commit.

  • Code quality
    • Added the pinned mypy v1.11.2 pre-commit hook using pre-commit/mirrors-mypy.
    • Configured it to check both Python (.py) and type stub (.pyi) files before commits.

Add the mypy static type checker to the pre-commit configuration to
improve Python type safety and catch potential bugs before commit.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d122f592-9cb6-4e7a-9839-f9d5435992ea

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pre-commit configuration adds a pinned mypy hook from pre-commit/mirrors-mypy, targeting both Python source files and type stub files.

Changes

Pre-commit type checking

Layer / File(s) Summary
Configure the mypy hook
.pre-commit-config.yaml
Adds pre-commit/mirrors-mypy at v1.11.2 with the mypy hook enabled for python and pyi file types.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding mypy to the pre-commit hooks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch maintenance/pre-commit-mypy-hook

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@knoepfel knoepfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you will need to make the following change in order for pre-commit run -a to be successful on the repository:

❯ git diff
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index b35ddb56..0a399f1d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -17,6 +17,9 @@ repos:
     hooks:
       - id: mypy
         types_or: [python, pyi]
+        args: [--enable-incomplete-feature=NewGenericSyntax]
+        additional_dependencies:
+          - types-PyYAML
   - repo: https://github.com/astral-sh/ruff-pre-commit
     rev: v0.15.22
     hooks:

- Bump mypy from v1.11.2 to v2.3.0
- Add Python 3.12 language_version for mypy, ruff-format, and ruff hooks
- Enable NewGenericSyntax feature in mypy
- Add types-PyYAML as additional dependency for mypy
@greenc-FNAL

Copy link
Copy Markdown
Contributor Author
+        args: [--enable-incomplete-feature=NewGenericSyntax]
+        additional_dependencies:
+          - types-PyYAML

Good catch, thank you.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             main     #738      +/-   ##
==========================================
- Coverage   83.84%   83.82%   -0.02%     
==========================================
  Files         172      172              
  Lines        7198     7203       +5     
  Branches      845      845              
==========================================
+ Hits         6035     6038       +3     
- Misses        882      884       +2     
  Partials      281      281              
Flag Coverage Δ
scripts 80.09% <ø> (-0.04%) ⬇️
unittests 85.70% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 12 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 852ff88...55b61aa. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@knoepfel
knoepfel merged commit 30ed526 into main Jul 24, 2026
39 checks passed
@knoepfel
knoepfel deleted the maintenance/pre-commit-mypy-hook branch July 24, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants