Skip to content

Commit 4e93aa0

Browse files
committed
inherit docstrings from baseclass
1 parent 731c22a commit 4e93aa0

File tree

7 files changed

+42
-2
lines changed

7 files changed

+42
-2
lines changed

src/zarr/core/common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,33 @@ def parse_order(data: Any) -> Literal["C", "F"]:
151151
if data in ("C", "F"):
152152
return cast(Literal["C", "F"], data)
153153
raise ValueError(f"Expected one of ('C', 'F'), got {data} instead.")
154+
155+
156+
def _inherit_docstrings(cls: type[Any]) -> type[Any]:
157+
"""
158+
Inherit docstrings from base class
159+
160+
Iterate over the methods of the class and if a method is missing a docstring,
161+
try to inherit one from a base class (ABC).
162+
163+
Parameters
164+
----------
165+
cls : object
166+
the class to inherit docstrings from
167+
168+
Returns
169+
-------
170+
cls
171+
the class with updated docstrings
172+
"""
173+
# Iterate over the methods of the class
174+
for name, method in cls.__dict__.items():
175+
# Skip if it's not a callable (method or function)
176+
if callable(method):
177+
# Get the corresponding method from the base class (ABC)
178+
for base in cls.__bases__:
179+
base_method = getattr(base, name, None)
180+
if base_method and not method.__doc__:
181+
method.__doc__ = base_method.__doc__
182+
break
183+
return cls

src/zarr/storage/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from zarr.storage.common import StoreLike, StorePath, make_store_path
22
from zarr.storage.local import LocalStore
3+
from zarr.storage.logging import LoggingStore
34
from zarr.storage.memory import MemoryStore
45
from zarr.storage.remote import RemoteStore
56
from zarr.storage.zip import ZipStore
67

78
__all__ = [
89
"LocalStore",
10+
"LoggingStore",
911
"MemoryStore",
1012
"RemoteStore",
1113
"StoreLike",

src/zarr/storage/local.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from zarr.abc.store import ByteRangeRequest, Store
1111
from zarr.core.buffer import Buffer
12-
from zarr.core.common import concurrent_map
12+
from zarr.core.common import _inherit_docstrings, concurrent_map
1313

1414
if TYPE_CHECKING:
1515
from collections.abc import AsyncGenerator, Iterable
@@ -66,6 +66,7 @@ def _put(
6666
return f.write(view)
6767

6868

69+
@_inherit_docstrings
6970
class LocalStore(Store):
7071
"""
7172
Local file system store.

src/zarr/storage/logging.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from zarr.abc.store import AccessMode, ByteRangeRequest, Store
1111
from zarr.core.buffer import Buffer
12+
from zarr.core.common import _inherit_docstrings
1213

1314
if TYPE_CHECKING:
1415
from collections.abc import AsyncGenerator, Generator, Iterable
@@ -17,6 +18,7 @@
1718
from zarr.core.common import AccessModeLiteral
1819

1920

21+
@_inherit_docstrings
2022
class LoggingStore(Store):
2123
"""
2224
Store wrapper that logs all calls to the wrapped store.

src/zarr/storage/memory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from zarr.abc.store import ByteRangeRequest, Store
66
from zarr.core.buffer import Buffer, gpu
7-
from zarr.core.common import concurrent_map
7+
from zarr.core.common import _inherit_docstrings, concurrent_map
88
from zarr.storage._utils import _normalize_interval_index
99

1010
if TYPE_CHECKING:
@@ -14,6 +14,7 @@
1414
from zarr.core.common import AccessModeLiteral
1515

1616

17+
@_inherit_docstrings
1718
class MemoryStore(Store):
1819
"""
1920
In-memory store for testing purposes.

src/zarr/storage/remote.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from zarr.abc.store import ByteRangeRequest, Store
88
from zarr.core.buffer import Buffer
9+
from zarr.core.common import _inherit_docstrings
910
from zarr.storage.common import _dereference_path
1011

1112
if TYPE_CHECKING:
@@ -24,6 +25,7 @@
2425
)
2526

2627

28+
@_inherit_docstrings
2729
class RemoteStore(Store):
2830
"""
2931
A remote Store based on FSSpec

src/zarr/storage/zip.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99

1010
from zarr.abc.store import ByteRangeRequest, Store
1111
from zarr.core.buffer import Buffer, BufferPrototype
12+
from zarr.core.common import _inherit_docstrings
1213

1314
if TYPE_CHECKING:
1415
from collections.abc import AsyncGenerator, Iterable
1516

1617
ZipStoreAccessModeLiteral = Literal["r", "w", "a"]
1718

1819

20+
@_inherit_docstrings
1921
class ZipStore(Store):
2022
"""
2123
Storage class using a ZIP file.

0 commit comments

Comments
 (0)