From f4c211fa2d70d71d8d4cedd2a77d0e877805ea95 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sun, 1 Oct 2023 00:08:00 -0700 Subject: [PATCH] Use Python 3.9-style type hinting for tuple[] and AbstractSet -> Set --- src/ocrmypdf/api.py | 2 +- src/ocrmypdf/imageops.py | 12 ++++++------ src/ocrmypdf/pluginspec.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ocrmypdf/api.py b/src/ocrmypdf/api.py index f0dd1e85..c731d25c 100644 --- a/src/ocrmypdf/api.py +++ b/src/ocrmypdf/api.py @@ -210,7 +210,7 @@ def create_options( return options -def ocr( # noqa: ruff: disable=D417 +def ocr( # noqa: D417 input_file: PathOrIO, output_file: PathOrIO, *, diff --git a/src/ocrmypdf/imageops.py b/src/ocrmypdf/imageops.py index 217675a2..fd23202c 100644 --- a/src/ocrmypdf/imageops.py +++ b/src/ocrmypdf/imageops.py @@ -7,7 +7,7 @@ from __future__ import annotations import logging from math import floor, sqrt -from typing import Optional, Tuple +from typing import Optional from PIL import Image @@ -43,13 +43,13 @@ def bytes_per_pixel(mode: str) -> int: def _calculate_downsample( - image_size: Tuple[int, int], + image_size: tuple[int, int], bytes_per_pixel: int, *, - max_size: Optional[Tuple[int, int]] = None, + max_size: Optional[tuple[int, int]] = None, max_pixels: Optional[int] = None, max_bytes: Optional[int] = None, -) -> Tuple[int, int]: +) -> tuple[int, int]: """Calculate image size required to downsample an image to fit limits. If no limit is exceeded, the input image's size is returned. @@ -106,10 +106,10 @@ def _calculate_downsample( def calculate_downsample( image: Image.Image, *, - max_size: Optional[Tuple[int, int]] = None, + max_size: Optional[tuple[int, int]] = None, max_pixels: Optional[int] = None, max_bytes: Optional[int] = None, -) -> Tuple[int, int]: +) -> tuple[int, int]: """Calculate image size required to downsample an image to fit limits. If no limit is exceeded, the input image's size is returned. diff --git a/src/ocrmypdf/pluginspec.py b/src/ocrmypdf/pluginspec.py index e217010c..6078355e 100644 --- a/src/ocrmypdf/pluginspec.py +++ b/src/ocrmypdf/pluginspec.py @@ -7,10 +7,10 @@ from __future__ import annotations from abc import ABC, abstractmethod from argparse import ArgumentParser, Namespace -from collections.abc import Sequence +from collections.abc import Sequence, Set from logging import Handler from pathlib import Path -from typing import TYPE_CHECKING, AbstractSet, NamedTuple +from typing import TYPE_CHECKING, NamedTuple import pluggy @@ -406,7 +406,7 @@ class OcrEngine(ABC): @staticmethod @abstractmethod - def languages(options: Namespace) -> AbstractSet[str]: + def languages(options: Namespace) -> Set[str]: """Returns the set of all languages that are supported by the engine. Languages are typically given in 3-letter ISO 3166-1 codes, but actually