Skip to content

Commit 08a7236

Browse files
authored
Merge pull request #281 from bgilbert/lowlevel
Add type hints to `_convert` and `lowlevel`; add type-checking infrastructure
2 parents fd2fdae + 32656fe commit 08a7236

File tree

5 files changed

+188
-72
lines changed

5 files changed

+188
-72
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ repos:
5353
name: Lint python code with flake8
5454
additional_dependencies: [flake8-bugbear, Flake8-pyproject]
5555

56+
- repo: https://github.com/pre-commit/mirrors-mypy
57+
rev: v1.11.2
58+
hooks:
59+
- id: mypy
60+
name: Check Python types
61+
additional_dependencies: [openslide-bin, pillow, types-setuptools]
62+
exclude: "^(doc/.*|openslide/(__init__|deepzoom)\\.py|tests/.*|examples/deepzoom/.*)$"
63+
5664
- repo: https://github.com/rstcheck/rstcheck
5765
rev: v6.2.4
5866
hooks:

openslide/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@
3232

3333
from openslide import lowlevel
3434

35-
# For the benefit of library users
36-
from openslide._version import __version__ # noqa: F401 module-imported-but-unused
35+
# Re-exports for the benefit of library users
36+
from openslide._version import ( # noqa: F401 module-imported-but-unused
37+
__version__ as __version__,
38+
)
39+
from openslide.lowlevel import (
40+
OpenSlideUnsupportedFormatError as OpenSlideUnsupportedFormatError,
41+
)
3742
from openslide.lowlevel import ( # noqa: F401 module-imported-but-unused
38-
OpenSlideError,
39-
OpenSlideUnsupportedFormatError,
40-
OpenSlideVersionError,
43+
OpenSlideVersionError as OpenSlideVersionError,
4144
)
45+
from openslide.lowlevel import OpenSlideError as OpenSlideError
4246

4347
__library_version__ = lowlevel.get_version()
4448

openslide/_convert.pyi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# openslide-python - Python bindings for the OpenSlide library
3+
#
4+
# Copyright (c) 2024 Benjamin Gilbert
5+
#
6+
# This library is free software; you can redistribute it and/or modify it
7+
# under the terms of version 2.1 of the GNU Lesser General Public License
8+
# as published by the Free Software Foundation.
9+
#
10+
# This library is distributed in the hope that it will be useful, but
11+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13+
# License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public License
16+
# along with this library; if not, write to the Free Software Foundation,
17+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
#
19+
20+
from typing import Protocol
21+
22+
class _Buffer(Protocol):
23+
# Python 3.12+ has collections.abc.Buffer
24+
def __buffer__(self, flags: int) -> memoryview: ...
25+
26+
def argb2rgba(buf: _Buffer) -> None: ...

0 commit comments

Comments
 (0)