From 819e1b9dd2bfeb6455524053b6d76b65d77bd66c Mon Sep 17 00:00:00 2001 From: Nulano Date: Thu, 4 Apr 2024 23:38:50 +0200 Subject: [PATCH] add type hints for Image.save --- src/PIL/Image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 09ddc770f28..8bae2974c11 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2374,7 +2374,9 @@ def transform(x, y, matrix): (w, h), Transform.AFFINE, matrix, resample, fillcolor=fillcolor ) - def save(self, fp, format=None, **params) -> None: + def save( + self, fp: StrOrBytesPath | IO[bytes], format: str | None = None, **params: Any + ) -> None: """ Saves this image under the given filename. If no format is specified, the format to use is determined from the filename @@ -2455,6 +2457,8 @@ def save(self, fp, format=None, **params) -> None: fp = builtins.open(filename, "r+b") else: fp = builtins.open(filename, "w+b") + else: + fp = cast(IO[bytes], fp) try: save_handler(self, fp, filename)