Skip to content

Commit a7fe885

Browse files
authored
Merge pull request silx-kit#350 from t20100/types
Added typing
2 parents a3988e8 + f5a3120 commit a7fe885

File tree

10 files changed

+293
-141
lines changed

10 files changed

+293
-141
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ jobs:
1717
with:
1818
python-version: '3.12'
1919
cache: 'pip'
20-
- run: python -m pip install --upgrade pip bandit black build flake8 isort twine
20+
- run: python -m pip install --upgrade pip bandit black build flake8 isort mypy numpy twine
2121
- run: bandit -c pyproject.toml -r .
2222
- run: black --check .
2323
- run: flake8
2424
- run: isort --check .
25+
- run: mypy
2526
- run: python -m build --sdist
2627
- run: python -m twine check dist/*
2728
# Build documentation

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"sphinx.ext.autodoc",
3030
"nbsphinx",
3131
"sphinx_rtd_theme",
32+
"sphinx_autodoc_typehints",
3233
]
3334

3435

doc/contribute.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ From the source directory:
4545

4646
bandit -c pyproject.toml -r .
4747

48+
* Check typing with `mypy <https://mypy.readthedocs.io>`_`::
49+
50+
mypy
51+
4852
Building documentation
4953
======================
5054

pyproject.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ doc = [
3838
"ipython",
3939
"nbsphinx",
4040
"sphinx",
41+
"sphinx-autodoc-typehints",
4142
"sphinx_rtd_theme",
4243
]
4344
test = [
@@ -81,3 +82,24 @@ extend-exclude = '''
8182
[tool.isort]
8283
profile = "black"
8384
skip_glob = ["lib"]
85+
86+
[tool.mypy]
87+
mypy_path = ["src"]
88+
packages = ["hdf5plugin"]
89+
strict = true
90+
implicit_optional = true
91+
warn_unused_configs = true
92+
93+
[[tool.mypy.overrides]]
94+
module = ["hdf5plugin.test"]
95+
disable_error_code = [
96+
"attr-defined",
97+
"no-untyped-def",
98+
]
99+
100+
[[tool.mypy.overrides]]
101+
module = [
102+
"blosc2",
103+
"hdf5plugin._config",
104+
]
105+
ignore_missing_imports = true

src/h5py.pyi

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from __future__ import annotations
2+
3+
"""mypy stubs for h5py usage in hdf5plugin"""
4+
5+
import ctypes
6+
from collections.abc import Buffer
7+
from types import TracebackType
8+
from typing import Any, BinaryIO, Tuple
9+
10+
from numpy.typing import ArrayLike, DTypeLike, NDArray
11+
12+
class DatasetId:
13+
def write_direct_chunk(self, offset: tuple[int, ...], data: Buffer) -> None: ...
14+
15+
class Dataset:
16+
def __getitem__(
17+
self, key: int | slice | tuple[int | slice, ...]
18+
) -> NDArray[Any]: ...
19+
@property
20+
def id(self) -> DatasetId: ...
21+
22+
class File:
23+
def __init__(
24+
self,
25+
name: str | BinaryIO,
26+
mode: str = "r",
27+
driver: str = None,
28+
backing_store: bool = None,
29+
): ...
30+
def __enter__(self) -> File: ...
31+
def __exit__(
32+
self,
33+
exc_type: type[BaseException] | None,
34+
exc_value: BaseException | None,
35+
traceback: TracebackType | None,
36+
) -> bool | None: ...
37+
def __getitem__(self, key: str) -> Any: ...
38+
def create_dataset(
39+
self,
40+
name: str,
41+
shape: tuple[int, ...] = None,
42+
dtype: DTypeLike = None,
43+
data: ArrayLike = None,
44+
chunks: tuple[int, ...] | bool | None = None,
45+
compression: filters.FilterRefBase = None,
46+
) -> Any: ...
47+
def flush(self) -> None: ...
48+
49+
class filters:
50+
class FilterRefBase:
51+
filter_id: int | None = None
52+
filter_options: Tuple[int, ...] = ()
53+
54+
def __len__(self) -> int: ...
55+
56+
class h5:
57+
@staticmethod
58+
def get_libversion() -> tuple[int, ...]: ...
59+
60+
class h5z:
61+
__file__: str
62+
63+
@staticmethod
64+
def filter_avail(filter_id: int) -> bool: ...
65+
@staticmethod
66+
def register_filter(filter_: ctypes.c_void_p) -> None: ...
67+
@staticmethod
68+
def unregister_filter(filter_id: int) -> bool: ...
69+
70+
class version:
71+
version_tuple: Tuple[int, ...]

0 commit comments

Comments
 (0)