Skip to content

Commit 2c6dcb9

Browse files
feat: add type annotations to errors and hash modules
- Add type annotations to errors.py (suggest method) - Add type annotations to hash.py (key_hash, uuid_from_buffer) - Enable strict mypy checking for these modules - Now 3 modules under strict checking: content_registry, errors, hash Increases type coverage incrementally following gradual adoption strategy. Related #1266 Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent a6bc04b commit 2c6dcb9

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ check_untyped_defs = true
166166
[[tool.mypy.overrides]]
167167
module = [
168168
"datajoint.content_registry",
169+
"datajoint.errors",
170+
"datajoint.hash",
169171
]
170172
disallow_untyped_defs = true
171173
disallow_incomplete_defs = true
@@ -185,10 +187,8 @@ module = [
185187
"datajoint.declare",
186188
"datajoint.dependencies",
187189
"datajoint.diagram",
188-
"datajoint.errors",
189190
"datajoint.expression",
190191
"datajoint.gc",
191-
"datajoint.hash",
192192
"datajoint.heading",
193193
"datajoint.jobs",
194194
"datajoint.lineage",

src/datajoint/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
class DataJointError(Exception):
1212
"""Base class for errors specific to DataJoint internal operation."""
1313

14-
def suggest(self, *args) -> "DataJointError":
14+
def suggest(self, *args: object) -> "DataJointError":
1515
"""
1616
Regenerate the exception with additional arguments.
1717
1818
Parameters
1919
----------
20-
*args : any
20+
*args : object
2121
Additional arguments to append to the exception.
2222
2323
Returns

src/datajoint/hash.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from __future__ import annotations
2+
13
import hashlib
24
import uuid
5+
from typing import Any
36

47

5-
def key_hash(mapping):
8+
def key_hash(mapping: dict[str, Any]) -> str:
69
"""
710
32-byte hash of the mapping's key values sorted by the key name.
811
This is often used to convert a long primary key value into a shorter hash.
@@ -13,7 +16,7 @@ def key_hash(mapping):
1316
return hashed.hexdigest()
1417

1518

16-
def uuid_from_buffer(buffer=b"", *, init_string=""):
19+
def uuid_from_buffer(buffer: bytes = b"", *, init_string: str = "") -> uuid.UUID:
1720
"""
1821
Compute MD5 hash of buffer data, returned as UUID.
1922

0 commit comments

Comments
 (0)