Skip to content

Commit 27391c7

Browse files
feat: add mypy type checking to pre-commit
- Add mypy configuration to pyproject.toml - Add mypy hook to pre-commit with type stubs - Start with lenient settings, strict checking for content_registry - All other modules excluded until fully typed (gradual adoption) Addresses #1266. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent b8645f8 commit 27391c7

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ repos:
3636
hooks:
3737
# lint github actions workflow yaml
3838
- id: actionlint
39-
40-
## Suggest to add pytest hook that runs unit test | Prerequisite: split unit/integration test
41-
## https://github.com/datajoint/datajoint-python/issues/1211
39+
- repo: https://github.com/pre-commit/mirrors-mypy
40+
rev: v1.14.1
41+
hooks:
42+
- id: mypy
43+
files: ^src/datajoint/
44+
additional_dependencies:
45+
- pydantic
46+
- pydantic-settings
47+
- types-PyMySQL
48+
- types-tqdm
49+
- pandas-stubs
50+
- numpy

pyproject.toml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,60 @@ quote-style = "double"
152152
indent-style = "space"
153153
line-ending = "auto"
154154

155+
[tool.mypy]
156+
python_version = "3.10"
157+
ignore_missing_imports = true
158+
# Start with lenient settings, gradually enable stricter checks
159+
warn_return_any = false
160+
warn_unused_ignores = false
161+
disallow_untyped_defs = false
162+
disallow_incomplete_defs = false
163+
check_untyped_defs = true
164+
165+
# Modules with complete type coverage - strict checking enabled
166+
[[tool.mypy.overrides]]
167+
module = [
168+
"datajoint.content_registry",
169+
]
170+
disallow_untyped_defs = true
171+
disallow_incomplete_defs = true
172+
warn_return_any = true
173+
174+
# Modules excluded from type checking until fully typed
175+
[[tool.mypy.overrides]]
176+
module = [
177+
"datajoint.admin",
178+
"datajoint.autopopulate",
179+
"datajoint.blob",
180+
"datajoint.builtin_codecs",
181+
"datajoint.cli",
182+
"datajoint.codecs",
183+
"datajoint.condition",
184+
"datajoint.connection",
185+
"datajoint.declare",
186+
"datajoint.dependencies",
187+
"datajoint.diagram",
188+
"datajoint.errors",
189+
"datajoint.expression",
190+
"datajoint.gc",
191+
"datajoint.hash",
192+
"datajoint.heading",
193+
"datajoint.jobs",
194+
"datajoint.lineage",
195+
"datajoint.logging",
196+
"datajoint.migrate",
197+
"datajoint.objectref",
198+
"datajoint.preview",
199+
"datajoint.schemas",
200+
"datajoint.settings",
201+
"datajoint.staged_insert",
202+
"datajoint.storage",
203+
"datajoint.table",
204+
"datajoint.user_tables",
205+
"datajoint.utils",
206+
]
207+
ignore_errors = true
208+
155209
[tool.setuptools]
156210
packages = ["datajoint"]
157211
package-dir = {"" = "src"}

0 commit comments

Comments
 (0)