From b6b55b2e657ba200d29b7e81f84c05c6040e1771 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 22 Oct 2023 17:49:26 +1100 Subject: [PATCH] once more into the linting breach! --- bookwyrm/models/bookwyrm_export_job.py | 3 ++- bookwyrm/tests/utils/test_tar.py | 1 + bookwyrm/utils/tar.py | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bookwyrm/models/bookwyrm_export_job.py b/bookwyrm/models/bookwyrm_export_job.py index 1185c867a..e4a6e314f 100644 --- a/bookwyrm/models/bookwyrm_export_job.py +++ b/bookwyrm/models/bookwyrm_export_job.py @@ -94,7 +94,8 @@ def json_export(user): # pylint: disable=too-many-locals, too-many-statements # reading goals reading_goals = models.AnnualGoal.objects.filter(user=user).distinct() goals_list = [] - # TODO: either error checking should be more sophisticated or maybe we don't need this try/except + # TODO: either error checking should be more sophisticated + # or maybe we don't need this try/except try: for goal in reading_goals: goals_list.append( diff --git a/bookwyrm/tests/utils/test_tar.py b/bookwyrm/tests/utils/test_tar.py index d1945c735..cb4e738d7 100644 --- a/bookwyrm/tests/utils/test_tar.py +++ b/bookwyrm/tests/utils/test_tar.py @@ -10,6 +10,7 @@ def read_tar(): yield tar +@pytest.fixture def write_tar(): archive_path = "/tmp/test.tar.gz" with open(archive_path, "wb") as archive_file: diff --git a/bookwyrm/utils/tar.py b/bookwyrm/utils/tar.py index 8f43b2c15..61c1019ec 100644 --- a/bookwyrm/utils/tar.py +++ b/bookwyrm/utils/tar.py @@ -8,14 +8,14 @@ from django.core.files import File class BookwyrmTarFile(tarfile.TarFile): """Create tar files for user exports""" - def write_bytes(self, data: bytes): + def write_bytes(self, data: bytes) -> None: """Add a file containing bytes to the archive""" buffer = io.BytesIO(data) info = tarfile.TarInfo("archive.json") info.size = len(data) self.addfile(info, fileobj=buffer) - def add_image(self, image, filename=None, directory=""): + def add_image(self, image: Any, filename: str = None, directory: Any = "") -> None: """ Add an image to the tar archive :param str filename: overrides the file name set by image @@ -32,12 +32,12 @@ class BookwyrmTarFile(tarfile.TarFile): self.addfile(info, fileobj=image) - def read(self, filename): + def read(self, filename: str) -> Any: """read data from the tar""" with self.extractfile(filename) as reader: return reader.read() - def write_image_to_file(self, filename, file_field): + def write_image_to_file(self, filename: str, file_field: Any) -> None: """add an image to the tar""" extension = filename.rsplit(".")[-1] with self.extractfile(filename) as reader: