diff --git a/docs/conf.py b/docs/conf.py index 240329c..9c76ed3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -54,3 +54,8 @@ extensions += ['sphinx.ext.extlinks'] # local + +nitpick_ignore += [ + # jaraco/jaraco.imaging#3 + ('py:class', 'PIL.Image.Image'), +] diff --git a/jaraco/imaging/__init__.py b/jaraco/imaging/__init__.py index e5bfba6..2f36594 100644 --- a/jaraco/imaging/__init__.py +++ b/jaraco/imaging/__init__.py @@ -7,7 +7,7 @@ import io import operator import struct -from collections import namedtuple +from typing import Iterable, NamedTuple, Tuple, Union import PIL.Image from importlib_resources import files @@ -15,23 +15,33 @@ import jaraco.clipboard -def calc_aspect(size): +def calc_aspect(size: Iterable[int]) -> float: "aspect = size[0] / size[1] # width/height" return functools.reduce(operator.truediv, size) -Dimensions = namedtuple('Dimensions', 'width height') +class Dimensions(NamedTuple): + width: int + height: int -def replace_height(size, new_height): +def replace_height(size: Dimensions, new_height: int) -> Dimensions: return Dimensions(size.width, new_height) -def replace_width(size, new_width): +def replace_width(size: Dimensions, new_width: int) -> Dimensions: return Dimensions(new_width, size.height) -def resize_with_aspect(image, max_size, *args, **kargs): +_PILImageParams = Union[int, Tuple[float, float, float, float], float, None] + + +def resize_with_aspect( + image: PIL.Image.Image, + max_size: Iterable[int], + *args: _PILImageParams, + **kargs: _PILImageParams, +) -> PIL.Image.Image: """ Resizes a PIL image to a maximum size specified while maintaining the aspect ratio of the image. @@ -55,15 +65,15 @@ def resize_with_aspect(image, max_size, *args, **kargs): # width is the limiting factor new_width = int(round(max_size.height * aspect)) new_size = replace_width(max_size, new_width) - return image.resize(new_size, *args, **kargs) + return image.resize(new_size, *args, **kargs) # type: ignore[arg-type] # Assume the user passed correct parameters or let it fail -def load_apng(): +def load_apng() -> PIL.Image.Image: apng = files() / 'sample.png' return PIL.Image.open(io.BytesIO(apng.read_bytes())) -def get_image(): +def get_image() -> PIL.Image.Image: """ Stolen from lpaste. TODO: extract to jaraco.clipboard or similar. """ @@ -75,7 +85,7 @@ def get_image(): return PIL.Image.open(img_stream) -def save_clipboard_image(): +def save_clipboard_image() -> None: parser = argparse.ArgumentParser() parser.add_argument('filename') filename = parser.parse_args().filename diff --git a/jaraco/imaging/py.typed b/jaraco/imaging/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/mypy.ini b/mypy.ini index efcb8cb..1d94e21 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,6 +1,6 @@ [mypy] # Is the project well-typed? -strict = False +strict = True # Early opt-in even when strict = False warn_unused_ignores = True @@ -13,3 +13,7 @@ explicit_package_bases = True disable_error_code = # Disable due to many false positives overload-overlap, + +# jaraco/jaraco.clipboard#15 +[mypy-jaraco.clipboard.*] +ignore_missing_imports = True diff --git a/newsfragments/3.feature.rst b/newsfragments/3.feature.rst new file mode 100644 index 0000000..88e9b7c --- /dev/null +++ b/newsfragments/3.feature.rst @@ -0,0 +1 @@ +Complete annotations and add ``py.typed`` marker -- by :user:`Avasam` diff --git a/pyproject.toml b/pyproject.toml index 4bd64bf..2fc0820 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,3 @@ save-cb-image = "jaraco.imaging:save_clipboard_image" [tool.setuptools_scm] - - -[tool.pytest-enabler.mypy] -# Disabled due to jaraco/skeleton#143