Merge pull request #7638 from radarhere/type_hints

This commit is contained in:
Hugo van Kemenade 2023-12-26 11:36:51 +02:00 committed by GitHub
commit ef0b0d232a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -24,7 +24,7 @@ class ContainerIO:
file (for example a TAR file). file (for example a TAR file).
""" """
def __init__(self, file, offset, length): def __init__(self, file, offset, length) -> None:
""" """
Create file object. Create file object.

View File

@ -16,6 +16,7 @@
from __future__ import annotations from __future__ import annotations
import io import io
from types import TracebackType
from . import ContainerIO from . import ContainerIO
@ -23,7 +24,7 @@ from . import ContainerIO
class TarIO(ContainerIO.ContainerIO): class TarIO(ContainerIO.ContainerIO):
"""A file object that provides read access to a given member of a TAR file.""" """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. Create file object.
@ -57,11 +58,16 @@ class TarIO(ContainerIO.ContainerIO):
super().__init__(self.fh, self.fh.tell(), size) super().__init__(self.fh, self.fh.tell(), size)
# Context manager support # Context manager support
def __enter__(self): def __enter__(self) -> TarIO:
return self 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() self.close()
def close(self): def close(self) -> None:
self.fh.close() self.fh.close()