Skip to content

Commit 8dbe50f

Browse files
docs: Continue docstring harmonization to NumPy style (batch 3)
Harmonized modules: - settings.py - Configuration system (pydantic-settings) - errors.py - Exception hierarchy - builtin_codecs.py - Built-in codec implementations All modules now use: - NumPy-style docstrings (Parameters, Returns, Raises, etc.) - `from __future__ import annotations` for deferred evaluation - Consistent single-line docstrings for simple classes/methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 96e2edf commit 8dbe50f

File tree

3 files changed

+268
-183
lines changed

3 files changed

+268
-183
lines changed

src/datajoint/builtin_codecs.py

Lines changed: 96 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,19 @@ def encode(self, value: bytes, *, key: dict | None = None, store_name: str | Non
167167
"""
168168
Store content and return metadata.
169169
170-
Args:
171-
value: Raw bytes to store.
172-
key: Primary key values (unused).
173-
store_name: Store to use. If None, uses default store.
174-
175-
Returns:
176-
Metadata dict: {hash, store, size}
170+
Parameters
171+
----------
172+
value : bytes
173+
Raw bytes to store.
174+
key : dict, optional
175+
Primary key values (unused).
176+
store_name : str, optional
177+
Store to use. If None, uses default store.
178+
179+
Returns
180+
-------
181+
dict
182+
Metadata dict: ``{hash, store, size}``.
177183
"""
178184
from .content_registry import put_content
179185

@@ -183,11 +189,16 @@ def decode(self, stored: dict, *, key: dict | None = None) -> bytes:
183189
"""
184190
Retrieve content by hash.
185191
186-
Args:
187-
stored: Metadata dict with 'hash' and optionally 'store'.
188-
key: Primary key values (unused).
192+
Parameters
193+
----------
194+
stored : dict
195+
Metadata dict with ``'hash'`` and optionally ``'store'``.
196+
key : dict, optional
197+
Primary key values (unused).
189198
190-
Returns:
199+
Returns
200+
-------
201+
bytes
191202
Original bytes.
192203
"""
193204
from .content_registry import get_content
@@ -275,19 +286,20 @@ def encode(
275286
"""
276287
Store content and return metadata.
277288
278-
Args:
279-
value: Content to store. Can be:
280-
- bytes: Raw bytes to store as file
281-
- str/Path: Path to local file or folder to upload
282-
key: Dict containing context for path construction:
283-
- _schema: Schema name
284-
- _table: Table name
285-
- _field: Field/attribute name
286-
- Other entries are primary key values
287-
store_name: Store to use. If None, uses default store.
288-
289-
Returns:
290-
Metadata dict suitable for ObjectRef.from_json()
289+
Parameters
290+
----------
291+
value : bytes, str, or Path
292+
Content to store: bytes (raw data), or str/Path (file/folder to upload).
293+
key : dict, optional
294+
Context for path construction with keys ``_schema``, ``_table``,
295+
``_field``, plus primary key values.
296+
store_name : str, optional
297+
Store to use. If None, uses default store.
298+
299+
Returns
300+
-------
301+
dict
302+
Metadata dict suitable for ``ObjectRef.from_json()``.
291303
"""
292304
from datetime import datetime, timezone
293305
from pathlib import Path
@@ -381,12 +393,17 @@ def decode(self, stored: dict, *, key: dict | None = None) -> Any:
381393
"""
382394
Create ObjectRef handle for lazy access.
383395
384-
Args:
385-
stored: Metadata dict from database.
386-
key: Primary key values (unused).
387-
388-
Returns:
389-
ObjectRef for accessing the stored content.
396+
Parameters
397+
----------
398+
stored : dict
399+
Metadata dict from database.
400+
key : dict, optional
401+
Primary key values (unused).
402+
403+
Returns
404+
-------
405+
ObjectRef
406+
Handle for accessing the stored content.
390407
"""
391408
from .objectref import ObjectRef
392409
from .content_registry import get_store_backend
@@ -396,7 +413,7 @@ def decode(self, stored: dict, *, key: dict | None = None) -> Any:
396413
return ObjectRef.from_json(stored, backend=backend)
397414

398415
def validate(self, value: Any) -> None:
399-
"""Validate that value is bytes, path, dict metadata, or (extension, data) tuple."""
416+
"""Validate value is bytes, path, dict metadata, or (ext, data) tuple."""
400417
from pathlib import Path
401418

402419
if isinstance(value, bytes):
@@ -463,13 +480,19 @@ def encode(self, value: Any, *, key: dict | None = None, store_name: str | None
463480
"""
464481
Read file and encode as filename + contents.
465482
466-
Args:
467-
value: Path to file (str or Path).
468-
key: Primary key values (unused).
469-
store_name: Unused for internal storage.
470-
471-
Returns:
472-
Bytes: filename (UTF-8) + null byte + file contents
483+
Parameters
484+
----------
485+
value : str or Path
486+
Path to file.
487+
key : dict, optional
488+
Primary key values (unused).
489+
store_name : str, optional
490+
Unused for internal storage.
491+
492+
Returns
493+
-------
494+
bytes
495+
Filename (UTF-8) + null byte + file contents.
473496
"""
474497
from pathlib import Path
475498

@@ -487,12 +510,17 @@ def decode(self, stored: bytes, *, key: dict | None = None) -> str:
487510
"""
488511
Extract file to download path and return local path.
489512
490-
Args:
491-
stored: Blob containing filename + null + contents.
492-
key: Primary key values (unused).
493-
494-
Returns:
495-
Path to extracted file as string.
513+
Parameters
514+
----------
515+
stored : bytes
516+
Blob containing filename + null + contents.
517+
key : dict, optional
518+
Primary key values (unused).
519+
520+
Returns
521+
-------
522+
str
523+
Path to extracted file.
496524
"""
497525
from pathlib import Path
498526

@@ -592,13 +620,19 @@ def encode(self, value: Any, *, key: dict | None = None, store_name: str | None
592620
"""
593621
Store path reference as JSON metadata.
594622
595-
Args:
596-
value: Relative path within the store (str).
597-
key: Primary key values (unused).
598-
store_name: Store where the file exists.
599-
600-
Returns:
601-
Metadata dict: {path, store}
623+
Parameters
624+
----------
625+
value : str
626+
Relative path within the store.
627+
key : dict, optional
628+
Primary key values (unused).
629+
store_name : str, optional
630+
Store where the file exists.
631+
632+
Returns
633+
-------
634+
dict
635+
Metadata dict: ``{path, store}``.
602636
"""
603637
from datetime import datetime, timezone
604638

@@ -629,12 +663,17 @@ def decode(self, stored: dict, *, key: dict | None = None) -> Any:
629663
"""
630664
Create ObjectRef handle for lazy access.
631665
632-
Args:
633-
stored: Metadata dict with path and store.
634-
key: Primary key values (unused).
635-
636-
Returns:
637-
ObjectRef for accessing the file.
666+
Parameters
667+
----------
668+
stored : dict
669+
Metadata dict with path and store.
670+
key : dict, optional
671+
Primary key values (unused).
672+
673+
Returns
674+
-------
675+
ObjectRef
676+
Handle for accessing the file.
638677
"""
639678
from .objectref import ObjectRef
640679
from .content_registry import get_store_backend

src/datajoint/errors.py

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,74 @@
11
"""
2-
Exception classes for the DataJoint library
2+
Exception classes for the DataJoint library.
3+
4+
This module defines the exception hierarchy for DataJoint errors.
35
"""
46

7+
from __future__ import annotations
8+
59

610
# --- Top Level ---
711
class DataJointError(Exception):
8-
"""
9-
Base class for errors specific to DataJoint internal operation.
10-
"""
12+
"""Base class for errors specific to DataJoint internal operation."""
1113

12-
def suggest(self, *args):
14+
def suggest(self, *args) -> "DataJointError":
1315
"""
14-
regenerate the exception with additional arguments
16+
Regenerate the exception with additional arguments.
17+
18+
Parameters
19+
----------
20+
*args : any
21+
Additional arguments to append to the exception.
1522
16-
:param args: addition arguments
17-
:return: a new exception of the same type with the additional arguments
23+
Returns
24+
-------
25+
DataJointError
26+
A new exception of the same type with the additional arguments.
1827
"""
1928
return self.__class__(*(self.args + args))
2029

2130

2231
# --- Second Level ---
2332
class LostConnectionError(DataJointError):
24-
"""
25-
Loss of server connection
26-
"""
33+
"""Loss of server connection."""
2734

2835

2936
class QueryError(DataJointError):
30-
"""
31-
Errors arising from queries to the database
32-
"""
37+
"""Errors arising from queries to the database."""
3338

3439

3540
# --- Third Level: QueryErrors ---
3641
class QuerySyntaxError(QueryError):
37-
"""
38-
Errors arising from incorrect query syntax
39-
"""
42+
"""Errors arising from incorrect query syntax."""
4043

4144

4245
class AccessError(QueryError):
43-
"""
44-
User access error: insufficient privileges.
45-
"""
46+
"""User access error: insufficient privileges."""
4647

4748

4849
class MissingTableError(DataJointError):
49-
"""
50-
Query on a table that has not been declared
51-
"""
50+
"""Query on a table that has not been declared."""
5251

5352

5453
class DuplicateError(QueryError):
55-
"""
56-
An integrity error caused by a duplicate entry into a unique key
57-
"""
54+
"""Integrity error caused by a duplicate entry into a unique key."""
5855

5956

6057
class IntegrityError(QueryError):
61-
"""
62-
An integrity error triggered by foreign key constraints
63-
"""
58+
"""Integrity error triggered by foreign key constraints."""
6459

6560

6661
class UnknownAttributeError(QueryError):
67-
"""
68-
User requests an attribute name not found in query heading
69-
"""
62+
"""User requests an attribute name not found in query heading."""
7063

7164

7265
class MissingAttributeError(QueryError):
73-
"""
74-
An error arising when a required attribute value is not provided in INSERT
75-
"""
66+
"""Required attribute value not provided in INSERT."""
7667

7768

7869
class MissingExternalFile(DataJointError):
79-
"""
80-
Error raised when an external file managed by DataJoint is no longer accessible
81-
"""
70+
"""External file managed by DataJoint is no longer accessible."""
8271

8372

8473
class BucketInaccessible(DataJointError):
85-
"""
86-
Error raised when a S3 bucket is inaccessible
87-
"""
74+
"""S3 bucket is inaccessible."""

0 commit comments

Comments
 (0)