From d400ef2b46914c693fa94bf5188cb1cee0383735 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 26 Dec 2023 12:18:38 +1100 Subject: [PATCH] Added type hints --- src/PIL/ContainerIO.py | 2 +- src/PIL/TarIO.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/PIL/ContainerIO.py b/src/PIL/ContainerIO.py index 387a4c182..64d042426 100644 --- a/src/PIL/ContainerIO.py +++ b/src/PIL/ContainerIO.py @@ -24,7 +24,7 @@ class ContainerIO: file (for example a TAR file). """ - def __init__(self, file, offset, length): + def __init__(self, file, offset, length) -> None: """ Create file object. diff --git a/src/PIL/TarIO.py b/src/PIL/TarIO.py index 26522d93f..c9923487d 100644 --- a/src/PIL/TarIO.py +++ b/src/PIL/TarIO.py @@ -16,6 +16,7 @@ from __future__ import annotations import io +from types import TracebackType from . import ContainerIO @@ -23,7 +24,7 @@ from . import ContainerIO class TarIO(ContainerIO.ContainerIO): """A file object that provides read access to a given member of a TAR file.""" - def __init__(self, tarfile, file): + def __init__(self, tarfile: str, file: str) -> None: """ Create file object. @@ -57,11 +58,16 @@ class TarIO(ContainerIO.ContainerIO): super().__init__(self.fh, self.fh.tell(), size) # Context manager support - def __enter__(self): + def __enter__(self) -> TarIO: return self - def __exit__(self, *args): + def __exit__( + self, + exc_type: type[BaseException] | None, + exc_val: BaseException | None, + exc_tb: TracebackType | None, + ) -> None: self.close() - def close(self): + def close(self) -> None: self.fh.close()