Skip to content

Commit

Permalink
Fix pyright type checking errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronkollasch committed Mar 12, 2023
1 parent 9a92beb commit a4d8c45
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/photomanager/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/photomanager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/photomanager/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
10 changes: 7 additions & 3 deletions src/photomanager/pyexiftool/pyexiftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import logging
import subprocess
import warnings
from io import BufferedIOBase
from os import fsencode
from typing import Optional

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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""
Expand Down

0 comments on commit a4d8c45

Please sign in to comment.