From a4d8c45b6bef755abf72975560efbe74ec5fadac Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Thu, 16 Feb 2023 17:03:06 -0500 Subject: [PATCH] Fix pyright type checking errors --- pyproject.toml | 3 ++- src/photomanager/actions/actions.py | 2 +- src/photomanager/cli.py | 2 +- src/photomanager/database.py | 4 ++-- src/photomanager/pyexiftool/pyexiftool.py | 10 +++++++--- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index aeb4aad..ccefaaa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,8 @@ include = ["src"] exclude = [ "**/node_modules", "**/__pycache__", - "src/typestubs" + "src/typestubs", + "src/photomanager/check_media_integrity/test_damage.py", ] defineConstant = { DEBUG = true } stubPath = "stubs" diff --git a/src/photomanager/actions/actions.py b/src/photomanager/actions/actions.py index 6796668..827cfda 100644 --- a/src/photomanager/actions/actions.py +++ b/src/photomanager/actions/actions.py @@ -69,7 +69,7 @@ def index( logger.info(f"Skipped {num_skipped_photos} items") if num_error_photos: # pragma: no cover logger.info(f"Encountered an error on {num_error_photos} items") - return dict( + return IndexResult( changed_uids=changed_uids, num_added_photos=num_added_photos, num_merged_photos=num_merged_photos, diff --git a/src/photomanager/cli.py b/src/photomanager/cli.py index b1b6b0d..c198069 100755 --- a/src/photomanager/cli.py +++ b/src/photomanager/cli.py @@ -15,7 +15,7 @@ from photomanager.hasher import DEFAULT_HASH_ALGO, HASH_ALGORITHMS, HashAlgorithm try: - from photomanager.check_media_integrity.check_mi import check_files + from photomanager.check_media_integrity.check_mi import check_files # type: ignore except ImportError as e: check_files_message = str(e) diff --git a/src/photomanager/database.py b/src/photomanager/database.py index c93bec2..4c70859 100644 --- a/src/photomanager/database.py +++ b/src/photomanager/database.py @@ -209,7 +209,7 @@ def db(self, db: dict): def from_dict(cls: Type[DB], db_dict: dict) -> DB: """Load a Database from a dictionary. Warning: can modify the dictionary.""" db = cls() - db.db = cast(DatabaseDict, db_dict) + db.db = cast(DatabaseDict, db_dict) # type: ignore return db @property @@ -541,7 +541,7 @@ def get_photos_to_collect( } else: photo_db = self.photo_db - for uid, photos in tqdm(photo_db.items()): + for photos in tqdm(photo_db.values()): highest_priority = min(photo.prio for photo in photos) stored_checksums: dict[str, int] = {} photos_marked_as_stored = [photo for photo in photos if photo.sto] diff --git a/src/photomanager/pyexiftool/pyexiftool.py b/src/photomanager/pyexiftool/pyexiftool.py index 30c24fb..6504d51 100644 --- a/src/photomanager/pyexiftool/pyexiftool.py +++ b/src/photomanager/pyexiftool/pyexiftool.py @@ -59,6 +59,7 @@ import logging import subprocess import warnings +from io import BufferedIOBase from os import fsencode from typing import Optional @@ -189,7 +190,7 @@ class ExifTool(object, metaclass=Singleton): def __init__(self, executable_=None): self.executable = executable if executable_ is None else executable_ self.running = False - self._process = None + self._process: Optional[subprocess.Popen] = None def start(self): """Start an ``exiftool`` process in batch mode for this instance. @@ -224,8 +225,9 @@ def terminate(self, wait_timeout=30): If the subprocess isn't running, this method will do nothing. """ - if not self.running: + if not self.running or self._process is None: return + assert self._process.stdin is not None and self._process.stdout is not None self._process.stdin.write(b"-stay_open\nFalse\n") self._process.stdin.flush() try: @@ -265,8 +267,10 @@ def execute(self, *params): .. note:: This is considered a low-level method, and should rarely be needed by application developers. """ - if not self.running: + if not self.running or self._process is None: raise ValueError("ExifTool instance not running.") + assert self._process.stdin is not None and self._process.stdout is not None + assert isinstance(self._process.stdout, BufferedIOBase) self._process.stdin.write(b"\n".join(params + (b"-execute\n",))) self._process.stdin.flush() output = b""