From 76809f09ef86d3feaaed3256a0e47dd5cec76520 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 22 Dec 2023 16:23:28 +0200 Subject: [PATCH 1/2] Add type hints for ImageMode --- src/PIL/ImageMode.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/PIL/ImageMode.py b/src/PIL/ImageMode.py index 54c3d01c4..661db24ad 100644 --- a/src/PIL/ImageMode.py +++ b/src/PIL/ImageMode.py @@ -23,18 +23,25 @@ _modes = None class ModeDescriptor: """Wrapper for mode strings.""" - def __init__(self, mode, bands, basemode, basetype, typestr): + def __init__( + self, + mode: str, + bands: str | tuple[str, ...], + basemode: str, + basetype: str | tuple[str, ...], + typestr: str, + ) -> None: self.mode = mode self.bands = bands self.basemode = basemode self.basetype = basetype self.typestr = typestr - def __str__(self): + def __str__(self) -> str: return self.mode -def getmode(mode): +def getmode(mode: str) -> ModeDescriptor: """Gets a mode descriptor for the given mode.""" global _modes if not _modes: From 17af8eca02fe7b4e0545811e5ab9843e26a030b1 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 23 Dec 2023 02:16:46 -0700 Subject: [PATCH 2/2] Add type hints for ImageMode Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/PIL/ImageMode.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PIL/ImageMode.py b/src/PIL/ImageMode.py index 661db24ad..d61dd6fea 100644 --- a/src/PIL/ImageMode.py +++ b/src/PIL/ImageMode.py @@ -26,9 +26,9 @@ class ModeDescriptor: def __init__( self, mode: str, - bands: str | tuple[str, ...], + bands: tuple[str, ...], basemode: str, - basetype: str | tuple[str, ...], + basetype: str, typestr: str, ) -> None: self.mode = mode