Skip to content

Commit 28e9cf8

Browse files
chore: update pre-commit hooks (#1508)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4e4f82c commit 28e9cf8

8 files changed

Lines changed: 108 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ jobs:
106106
- uses: actions/checkout@v6
107107

108108
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
109+
- name: Check mypy deps are in sync with project deps
110+
run: hatch run typing:check
111+
109112
- name: Run Linters
110113
run: |
111114
hatch run typing:test

.pre-commit-config.yaml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
- id: trailing-whitespace
2323

2424
- repo: https://github.com/python-jsonschema/check-jsonschema
25-
rev: 0.37.0
25+
rev: 0.37.2
2626
hooks:
2727
- id: check-github-workflows
2828

@@ -39,28 +39,50 @@ repos:
3939
types_or: [yaml, html, json]
4040

4141
- repo: https://github.com/pre-commit/mirrors-mypy
42-
rev: "v1.19.1"
42+
rev: "v2.1.0"
4343
hooks:
4444
- id: mypy
4545
files: ipykernel
4646
stages: [manual]
4747
args: ["--install-types", "--non-interactive"]
4848
additional_dependencies:
4949
[
50-
"traitlets>=5.13",
51-
"ipython>=8.16.1",
52-
"jupyter_client>=8.5",
53-
"appnope",
50+
"appnope>=0.1.2",
51+
"comm>=0.1.1",
52+
"debugpy>=1.6.5",
53+
"ipython>=7.23.1",
54+
"jupyter_client>=8.9.0",
55+
"jupyter_core>=5.1",
56+
"matplotlib-inline>=0.1",
57+
"nest_asyncio2>=1.7.0",
58+
"packaging>=22",
59+
"psutil>=5.7",
60+
"pyzmq>=25",
61+
"tornado>=6.4.1",
62+
"traitlets>=5.4.0",
5463
]
5564

65+
- repo: local
66+
hooks:
67+
- id: check-mypy-deps
68+
name: mypy deps in sync with project deps
69+
entry: python scripts/check_mypy_deps.py
70+
language: python
71+
pass_filenames: false
72+
always_run: true
73+
additional_dependencies:
74+
- "pyyaml"
75+
- "packaging"
76+
- "tomli; python_version < '3.11'"
77+
5678
- repo: https://github.com/adamchainz/blacken-docs
5779
rev: "1.20.0"
5880
hooks:
5981
- id: blacken-docs
6082
additional_dependencies: [black==23.7.0]
6183

6284
- repo: https://github.com/codespell-project/codespell
63-
rev: "v2.4.1"
85+
rev: "v2.4.2"
6486
hooks:
6587
- id: codespell
6688
args: ["-L", "sur,nd"]
@@ -73,7 +95,7 @@ repos:
7395
- id: rst-inline-touching-normal
7496

7597
- repo: https://github.com/astral-sh/ruff-pre-commit
76-
rev: v0.15.4
98+
rev: v0.15.16
7799
hooks:
78100
- id: ruff-check
79101
types_or: [python, jupyter]
@@ -82,7 +104,7 @@ repos:
82104
types_or: [python, jupyter]
83105

84106
- repo: https://github.com/scientific-python/cookie
85-
rev: "2026.03.02"
107+
rev: "2026.04.04"
86108
hooks:
87109
- id: sp-repo-review
88110
additional_dependencies: ["repo-review[cli]"]

ipykernel/comm/comm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
# this is the class that will be created if we do comm.create_comm
19-
class BaseComm(comm.base_comm.BaseComm): # type:ignore[misc]
19+
class BaseComm(comm.base_comm.BaseComm):
2020
"""The base class for comms."""
2121

2222
kernel: Optional["Kernel"] = None
@@ -90,7 +90,7 @@ def __init__(
9090
kernel = kwargs.pop("kernel", None)
9191
if target_name:
9292
kwargs["target_name"] = target_name
93-
BaseComm.__init__(self, data=data, metadata=metadata, buffers=buffers, **kwargs) # type:ignore[call-arg]
93+
BaseComm.__init__(self, data=data, metadata=metadata, buffers=buffers, **kwargs)
9494
# only re-add kernel if explicitly provided
9595
if had_kernel:
9696
kwargs["kernel"] = kernel

ipykernel/comm/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
logger = logging.getLogger("ipykernel.comm")
1515

1616

17-
class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurable): # type:ignore[misc]
17+
class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurable):
1818
"""A comm manager."""
1919

2020
kernel = traitlets.Instance("ipykernel.kernelbase.Kernel")

ipykernel/eventloops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def _schedule_exit(delay):
301301
else:
302302
import asyncio
303303

304-
import nest_asyncio2
304+
import nest_asyncio2 # type: ignore[import-untyped]
305305

306306
nest_asyncio2.apply()
307307

ipykernel/kernelbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ async def dispatch_shell(self, msg, /, subshell_id: str | None = None):
441441
# Only abort execute requests
442442
if msg_type == "execute_request":
443443
if subshell_id is None:
444-
aborting = self._aborting # type:ignore[unreachable]
444+
aborting = self._aborting
445445
else:
446446
aborting = self.shell_channel_thread.manager.get_subshell_aborting(subshell_id)
447447
if aborting:

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,16 @@ dependencies = ["pre-commit"]
113113
detached = true
114114
[tool.hatch.envs.typing.scripts]
115115
test = "pre-commit run --all-files --hook-stage manual mypy"
116+
check = "pre-commit run --all-files check-mypy-deps"
116117

117118
[tool.hatch.envs.lint]
118119
dependencies = ["pre-commit"]
119120
detached = true
120121
[tool.hatch.envs.lint.scripts]
121122
build = [
122123
"pre-commit run --all-files ruff-check",
123-
"pre-commit run --all-files ruff-format"
124+
"pre-commit run --all-files ruff-format",
125+
"pre-commit run --all-files check-mypy-deps",
124126
]
125127

126128
[tool.mypy]

scripts/check_mypy_deps.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python
2+
"""Verify that the mypy hook's additional_dependencies in .pre-commit-config.yaml
3+
includes all runtime dependencies declared in pyproject.toml.
4+
5+
Run directly or via pre-commit (check-mypy-deps hook).
6+
"""
7+
8+
from __future__ import annotations
9+
10+
import sys
11+
12+
try:
13+
import tomllib
14+
except ImportError:
15+
import tomli as tomllib # type: ignore[no-reuse-def]
16+
17+
import yaml
18+
from packaging.requirements import Requirement
19+
20+
21+
def normalize(name: str) -> str:
22+
return name.lower().replace("-", "_").replace(".", "_")
23+
24+
25+
def main() -> int:
26+
with open("pyproject.toml", "rb") as f:
27+
pyproject = tomllib.load(f)
28+
29+
with open(".pre-commit-config.yaml") as f:
30+
pre_commit = yaml.safe_load(f)
31+
32+
project_deps: list[str] = pyproject["project"]["dependencies"]
33+
project_packages = {normalize(Requirement(dep).name) for dep in project_deps}
34+
35+
mypy_additional: list[str] | None = None
36+
for repo in pre_commit["repos"]:
37+
for hook in repo.get("hooks", []):
38+
if hook["id"] == "mypy":
39+
mypy_additional = hook.get("additional_dependencies", [])
40+
break
41+
if mypy_additional is not None:
42+
break
43+
44+
if mypy_additional is None:
45+
print("ERROR: mypy hook not found in .pre-commit-config.yaml")
46+
return 1
47+
48+
mypy_packages = {normalize(Requirement(dep).name) for dep in mypy_additional}
49+
50+
missing = project_packages - mypy_packages
51+
if missing:
52+
print(
53+
"ERROR: The following project dependencies are missing from the mypy\n"
54+
"hook's additional_dependencies in .pre-commit-config.yaml:\n"
55+
)
56+
for pkg in sorted(missing):
57+
print(f" {pkg}")
58+
print("\nAdd them to the `additional_dependencies` list of the mypy hook.")
59+
return 1
60+
61+
print("OK: mypy additional_dependencies covers all project runtime dependencies.")
62+
return 0
63+
64+
65+
if __name__ == "__main__":
66+
sys.exit(main())

0 commit comments

Comments
 (0)