From a89e52a286cb8b91b9509d2db6c341e951fdca88 Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 17 Mar 2022 01:46:33 -0400 Subject: [PATCH] Fix mypy typing --- mypy.ini | 1 + win2xcur/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mypy.ini b/mypy.ini index 5a12ab1..f9864c6 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,3 +1,4 @@ [mypy] ignore_missing_imports = True strict = true +plugins = numpy.typing.mypy_plugin diff --git a/win2xcur/utils.py b/win2xcur/utils.py index 3ff8729..5cb62af 100644 --- a/win2xcur/utils.py +++ b/win2xcur/utils.py @@ -1,12 +1,12 @@ -from typing import cast +from typing import Any -import numpy +import numpy as np def premultiply_alpha(source: bytes) -> bytes: - buffer = numpy.frombuffer(source, dtype=numpy.uint8).astype(numpy.double) + buffer: np.ndarray[Any, np.dtype[np.double]] = np.frombuffer(source, dtype=np.uint8).astype(np.double) alpha = buffer[3::4] / 255.0 buffer[0::4] *= alpha buffer[1::4] *= alpha buffer[2::4] *= alpha - return cast(bytes, buffer.astype(numpy.uint8).tobytes()) + return buffer.astype(np.uint8).tobytes()