diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ff10f765..eb7716ca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,3 +30,12 @@ repos: hooks: - id: pyupgrade args: ["--py36-plus"] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910 + hooks: + - id: mypy + additional_dependencies: + - types-toml + - types-setuptools + - types-requests + - types-Pillow diff --git a/src/ocrmypdf/_exec/tesseract.py b/src/ocrmypdf/_exec/tesseract.py index 25f09bbd..33ead41e 100644 --- a/src/ocrmypdf/_exec/tesseract.py +++ b/src/ocrmypdf/_exec/tesseract.py @@ -20,6 +20,7 @@ from typing import List, Optional from PIL import Image +from ocrmypdf.api import StrPath from ocrmypdf.exceptions import ( MissingDependencyError, SubprocessOutputError, @@ -250,7 +251,8 @@ def generate_hocr( # Reminder: test suite tesseract test plugins will break after any changes # to the number of order parameters here - args_tesseract.extend([input_file, prefix, 'hocr', 'txt'] + tessconfig) + args_tesseract.extend([os.fspath(input_file), os.fspath(prefix), 'hocr', 'txt']) + args_tesseract.extend(tessconfig) try: p = run(args_tesseract, stdout=PIPE, stderr=STDOUT, timeout=timeout, check=True) stdout = p.stdout @@ -324,7 +326,8 @@ def generate_pdf( # Reminder: test suite tesseract test plugins might break after any changes # to the number of order parameters here - args_tesseract.extend([input_file, prefix, 'pdf', 'txt'] + tessconfig) + args_tesseract.extend([os.fspath(input_file), os.fspath(prefix), 'pdf', 'txt']) + args_tesseract.extend(tessconfig) try: p = run(args_tesseract, stdout=PIPE, stderr=STDOUT, timeout=timeout, check=True) stdout = p.stdout diff --git a/src/ocrmypdf/api.py b/src/ocrmypdf/api.py index 65ab910b..de3561e4 100644 --- a/src/ocrmypdf/api.py +++ b/src/ocrmypdf/api.py @@ -31,7 +31,7 @@ except ModuleNotFoundError: coloredlogs = None -StrPath = Union[os.PathLike, AnyStr] +StrPath = Union[Path, AnyStr] PathOrIO = Union[BinaryIO, StrPath] _api_lock = threading.Lock() diff --git a/src/ocrmypdf/cli.py b/src/ocrmypdf/cli.py index 43ea1de7..199e0c41 100644 --- a/src/ocrmypdf/cli.py +++ b/src/ocrmypdf/cli.py @@ -6,7 +6,7 @@ import argparse -from typing import Optional, Type, TypeVar +from typing import Any, Callable, Optional, TypeVar from ocrmypdf._version import PROGRAM_NAME as _PROGRAM_NAME from ocrmypdf._version import __version__ as _VERSION @@ -14,7 +14,9 @@ from ocrmypdf._version import __version__ as _VERSION T = TypeVar('T') -def numeric(basetype: Type[T], min_: Optional[T] = None, max_: Optional[T] = None): +def numeric( + basetype: Callable[[Any], T], min_: Optional[T] = None, max_: Optional[T] = None +): """Validator for numeric params""" min_ = basetype(min_) if min_ is not None else None max_ = basetype(max_) if max_ is not None else None