Fix mypy typing

This commit is contained in:
Quantum 2022-03-17 01:46:33 -04:00
parent 5c03c08a61
commit a89e52a286
2 changed files with 5 additions and 4 deletions

View file

@ -1,3 +1,4 @@
[mypy]
ignore_missing_imports = True
strict = true
plugins = numpy.typing.mypy_plugin

View file

@ -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()