Skip to content

Commit

Permalink
Fix interaction with old Python and singledispatch and typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarlow83 committed May 10, 2023
1 parent 214f6ec commit 731b2fc
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/ocrmypdf/imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
from functools import singledispatch
from math import floor, sqrt
from typing import Optional, Tuple

from PIL import Image

Expand All @@ -19,6 +20,13 @@
Resampling = Image # type: ignore


# While from __future__ import annotations, we use singledispatch here, which
# does not support annotations. Disable check about using old-style typing
# until Python 3.10, OR when drop singledispatch in ocrmypdf 15.
# ruff: noqa: UP006
# ruff: noqa: UP007


log = logging.getLogger(__name__)


Expand All @@ -37,13 +45,13 @@ def bytes_per_pixel(mode: str) -> int:

@singledispatch
def calculate_downsample(
image_size: tuple[int, int],
image_size: Tuple[int, int],
bytes_per_pixel: int,
*,
max_size: tuple[int, int] | None = None,
max_pixels: int | None = None,
max_bytes: int | None = None,
) -> tuple[int, int]:
max_size: Optional[Tuple[int, int]] = None,
max_pixels: Optional[int] = None,
max_bytes: Optional[int] = None,
) -> 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.
Expand Down Expand Up @@ -102,10 +110,10 @@ def _(
image: Image.Image,
arg: None = None,
*,
max_size: tuple[int, int] | None = None,
max_pixels: int | None = None,
max_bytes: int | None = None,
) -> tuple[int, int]:
max_size: Optional[Tuple[int, int]] = None,
max_pixels: Optional[int] = None,
max_bytes: Optional[int] = None,
) -> 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.
Expand Down

0 comments on commit 731b2fc

Please sign in to comment.