From 872ce0b0a08cdfbd07902ee77b68ea01faa97bd8 Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Tue, 20 Oct 2026 00:56:27 -0500 Subject: [PATCH] Temporarily ignore Pillow ImageFile context manager return type Pillow 13.0.0 changes the context manager to return typing.Self, which was added in Python 3.11, but we configure Mypy to assume Python 3.10+. This causes pre-commit to fail: openslide/__init__.py:395: error: Returning Any from function declared to return "str | None" [no-any-return] Mypy should check 3.10+ syntax as long as we support 3.10, so re-add the ignore for now. Bump the Mypy Pillow dependency to ensure we don't have the opposite problem with old prek caches. Signed-off-by: Benjamin Gilbert --- .pre-commit-config.yaml | 2 +- openslide/__init__.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0064d032..d2c0fc91 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,7 +40,7 @@ repos: name: Check Python types priority: 0 # Pillow is ignored in dependabot.yml - additional_dependencies: [flask, openslide-bin, pillow >= 12.1.0, types-PyYAML, types-setuptools] + additional_dependencies: [flask, openslide-bin, pillow >= 13.0.0, types-PyYAML, types-setuptools] - repo: https://github.com/rstcheck/rstcheck rev: v6.3.0 diff --git a/openslide/__init__.py b/openslide/__init__.py index f3b4844d..f8c6e367 100644 --- a/openslide/__init__.py +++ b/openslide/__init__.py @@ -392,7 +392,8 @@ def detect_format(cls, filename: lowlevel.Filename) -> str | None: If the file format is not recognized, return None.""" try: with Image.open(filename) as img: - return img.format + # mypy will think img is Any until we drop Python 3.10 + return img.format # type: ignore[no-any-return] except OSError: return None