Fix some typing issues
This commit is contained in:
@@ -57,9 +57,11 @@ log = logging.getLogger(__name__)
|
||||
tls = threading.local()
|
||||
tls.pageno = None
|
||||
|
||||
|
||||
def _set_logging_tls(tls):
|
||||
"""Inject current page number (when available) into log records."""
|
||||
old_factory = logging.getLogRecordFactory()
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
record = old_factory(*args, **kwargs)
|
||||
if hasattr(tls, 'pageno'):
|
||||
@@ -72,7 +74,7 @@ def _set_logging_tls(tls):
|
||||
_set_logging_tls(tls)
|
||||
|
||||
|
||||
def set_thread_pageno(pageno:int):
|
||||
def set_thread_pageno(pageno: int | None):
|
||||
"""Set page number (1-based) that the current thread is processing."""
|
||||
tls.pageno = pageno
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class OcrmypdfPluginManager(pluggy.PluginManager):
|
||||
def __init__(
|
||||
self,
|
||||
*args,
|
||||
plugins: list[str | Path],
|
||||
plugins: Sequence[str | Path],
|
||||
builtins: bool = True,
|
||||
**kwargs,
|
||||
):
|
||||
@@ -101,7 +101,7 @@ class OcrmypdfPluginManager(pluggy.PluginManager):
|
||||
|
||||
|
||||
def get_plugin_manager(
|
||||
plugins: list[str | Path] | None = None, builtins=True
|
||||
plugins: Sequence[str | Path] | None = None, builtins=True
|
||||
) -> OcrmypdfPluginManager:
|
||||
return OcrmypdfPluginManager(
|
||||
project_name='ocrmypdf',
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import os
|
||||
import sys
|
||||
import threading
|
||||
from argparse import Namespace
|
||||
from collections.abc import Iterable
|
||||
from collections.abc import Iterable, Sequence
|
||||
from enum import IntEnum
|
||||
from io import IOBase
|
||||
from pathlib import Path
|
||||
@@ -414,7 +414,7 @@ def pdf_to_hocr( # noqa: D417
|
||||
continue_on_soft_render_error: bool | None = None,
|
||||
invalidate_digital_signatures: bool | None = None,
|
||||
plugin_manager=None,
|
||||
plugins: Iterable[StrPath] | None = None,
|
||||
plugins: Sequence[StrPath] | None = None,
|
||||
keep_temporary_files: bool | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
@@ -483,7 +483,7 @@ def hocr_to_ocr_pdf( # noqa: D417
|
||||
color_conversion_strategy: str | None = None,
|
||||
fast_web_view: float | None = None,
|
||||
plugin_manager=None,
|
||||
plugins: Iterable[StrPath] | None = None,
|
||||
plugins: Sequence[StrPath] | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
"""Run OCRmyPDF on a work folder and produce an output PDF.
|
||||
|
||||
@@ -324,7 +324,11 @@ def pikepdf_enable_mmap() -> None:
|
||||
pikepdf._core.set_access_default_mmap(True)
|
||||
log.debug(
|
||||
"pikepdf mmap "
|
||||
+ ('enabled' if pikepdf._core.get_access_default_mmap() else 'disabled')
|
||||
+ (
|
||||
'enabled'
|
||||
if pikepdf._core.get_access_default_mmap() # type: ignore[attr-defined]
|
||||
else 'disabled'
|
||||
)
|
||||
)
|
||||
except AttributeError:
|
||||
log.debug("pikepdf mmap not available")
|
||||
|
||||
@@ -32,6 +32,7 @@ from pikepdf import (
|
||||
PdfImage,
|
||||
PdfInlineImage,
|
||||
PdfMatrix,
|
||||
Stream,
|
||||
UnsupportedImageTypeError,
|
||||
parse_content_stream,
|
||||
)
|
||||
@@ -357,7 +358,7 @@ class ImageInfo:
|
||||
if inline is not None:
|
||||
self._origin = 'inline'
|
||||
pim = inline
|
||||
elif pdfimage is not None:
|
||||
elif pdfimage is not None and isinstance(pdfimage, Stream):
|
||||
self._origin = 'xobject'
|
||||
pim = PdfImage(pdfimage)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user