typing: fix path and numeric issues

This commit is contained in:
James R. Barlow
2021-08-27 00:23:38 -07:00
parent 53cd04799a
commit e402d5cb4b
4 changed files with 19 additions and 5 deletions
+9
View File
@@ -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
+5 -2
View File
@@ -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
+1 -1
View File
@@ -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()
+4 -2
View File
@@ -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