Skip to content

Commit

Permalink
Merge pull request #7638 from radarhere/type_hints
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 26, 2023
2 parents 36b40f7 + d400ef2 commit ef0b0d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/PIL/ContainerIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions src/PIL/TarIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
from __future__ import annotations

import io
from types import TracebackType

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.
Expand Down Expand Up @@ -57,11 +58,16 @@ def __init__(self, tarfile, file):
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()

0 comments on commit ef0b0d2

Please sign in to comment.