From be37bd399057596258c4c6fd032ee86248bdb9e0 Mon Sep 17 00:00:00 2001 From: Joel Ray Holveck Date: Wed, 24 Jun 2026 18:02:40 -0700 Subject: [PATCH] Update MyPy to 2.1.0, with necessary fixes MyPy 2.1.0 found some places where the type changes from #521 weren't correctly propagated. This should supercede PR #524 (dependabot's bump). --- pyproject.toml | 2 +- src/mss/linux/xlib.py | 4 +++- src/mss/tools.py | 4 +++- src/tests/bench_bgra2rgb.py | 2 +- src/tests/bench_general.py | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8c1145a1..b6c3067b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ mss = "mss.__main__:main" dev = [ "build==1.5.0", "lxml==6.1.1", - "mypy==1.20.2", + "mypy==2.1.0", "ruff==0.15.18", "twine==6.2.0", "typing_extensions==4.15.0", diff --git a/src/mss/linux/xlib.py b/src/mss/linux/xlib.py index bd95049c..3bd4a4a8 100644 --- a/src/mss/linux/xlib.py +++ b/src/mss/linux/xlib.py @@ -40,6 +40,8 @@ from mss.screenshot import ScreenShot if TYPE_CHECKING: + from threading import Thread + from mss.models import CFunctions, Monitor, Monitors __all__ = () @@ -259,7 +261,7 @@ class XWindowAttributes(Structure): ) -_ERROR = {} +_ERROR: dict[Thread, dict[str, Any]] = {} _X11 = find_library("X11") _XFIXES = find_library("Xfixes") _XRANDR = find_library("Xrandr") diff --git a/src/mss/tools.py b/src/mss/tools.py index 9e4b7e9f..2524c2a0 100644 --- a/src/mss/tools.py +++ b/src/mss/tools.py @@ -142,7 +142,9 @@ def parse_edid(edid_data: bytes) -> dict: return rv -def to_png(data: bytes, size: tuple[int, int], /, *, level: int = 6, output: Path | str | None = None) -> bytes | None: +def to_png( + data: bytes | memoryview[int], size: tuple[int, int], /, *, level: int = 6, output: Path | str | None = None +) -> bytes | None: """Dump data to a PNG file. If `output` is `None`, create no file but return the whole PNG data. diff --git a/src/tests/bench_bgra2rgb.py b/src/tests/bench_bgra2rgb.py index 27eadb0d..77f2f9d3 100644 --- a/src/tests/bench_bgra2rgb.py +++ b/src/tests/bench_bgra2rgb.py @@ -37,7 +37,7 @@ from mss.screenshot import ScreenShot -def mss_rgb(im: ScreenShot) -> bytes: +def mss_rgb(im: ScreenShot) -> memoryview: return im.rgb diff --git a/src/tests/bench_general.py b/src/tests/bench_general.py index d7d223af..c32e3e7c 100644 --- a/src/tests/bench_general.py +++ b/src/tests/bench_general.py @@ -45,7 +45,7 @@ def grab(sct: MSS) -> ScreenShot: return sct.grab(monitor) -def access_rgb(sct: MSS) -> bytes: +def access_rgb(sct: MSS) -> memoryview: im = grab(sct) return im.rgb