Skip to content

Commit

Permalink
STY: Address additional ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shartzog committed Jan 3, 2024
1 parent 220de15 commit 21d9f1b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
17 changes: 10 additions & 7 deletions pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@
Optional,
Sequence,
Set,
TYPE_CHECKING,
Tuple,
Union,
cast,
overload,
)

try:
# Python 3.8+: https://peps.python.org/pep-0586
from typing import Literal
except ImportError:
from typing_extensions import Literal

from ._cmap import build_char_map, unknown_char_map
from ._protocols import PdfReaderProtocol, PdfWriterProtocol
from ._text_extraction import (
Expand Down Expand Up @@ -92,6 +87,14 @@
StreamObject,
)

if TYPE_CHECKING:
try:
# Python 3.8+: https://peps.python.org/pep-0586
from typing import Literal
except ImportError:
from typing_extensions import Literal


MERGE_CROP_BOX = "cropbox" # pypdf<=3.4.0 used 'trimbox'


Expand Down Expand Up @@ -2023,7 +2026,7 @@ def extract_text(
"""
extraction_mode: Literal["plain", "layout"] = kwargs.get("extraction_mode", "plain")
if extraction_mode not in ["plain", "layout"]:
raise ValueError(f"Invalid text extraction mode {repr(extraction_mode)}")
raise ValueError(f"Invalid text extraction mode '{extraction_mode}'")

Check warning on line 2029 in pypdf/_page.py

View check run for this annotation

Codecov / codecov/patch

pypdf/_page.py#L2029

Added line #L2029 was not covered by tests
if extraction_mode == "layout":
return self._layout_mode_text(

Check warning on line 2031 in pypdf/_page.py

View check run for this annotation

Codecov / codecov/patch

pypdf/_page.py#L2031

Added line #L2031 was not covered by tests
space_vertically=kwargs.get("layout_mode_space_vertically", True),
Expand Down
4 changes: 2 additions & 2 deletions pypdf/_text_extraction/_layout_mode/_fixed_width_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from itertools import groupby
from pathlib import Path
from typing import Any, Dict, Iterator, List, Tuple, Union
from typing import Dict, Iterator, List, Tuple, Union

try:
# Python 3.8+: https://peps.python.org/pep-0586
Expand Down Expand Up @@ -291,7 +291,7 @@ def _set_state_param(op: bytes, opands: List, xform_stack: XformStack) -> None:


def text_show_operations(
ops: Iterator[Tuple[List, bytes]], fonts: Dict[str, Font], debug_path=Union[Path, None]
ops: Iterator[Tuple[List, bytes]], fonts: Dict[str, Font], debug_path: Union[Path, None] = None
) -> List[BTGroup]:
"""
Extract text from BT/ET operator pairs
Expand Down
3 changes: 2 additions & 1 deletion pypdf/_text_extraction/_layout_mode/_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def font_size_matrix(self) -> List[float]:
return [self.font_size * (self.Tz / 100.0), 0.0, 0.0, self.font_size, 0.0, self.Ts]

Check warning on line 162 in pypdf/_text_extraction/_layout_mode/_fonts.py

View check run for this annotation

Codecov / codecov/patch

pypdf/_text_extraction/_layout_mode/_fonts.py#L162

Added line #L162 was not covered by tests

def displacement_matrix(self, word: Union[str, None] = None, TD_offset: float = 0.0) -> List[float]:
"""Text displacement matrix
"""
Text displacement matrix
Args:
word (str, optional): Defaults to None in which case self.txt displacement is
Expand Down
4 changes: 1 addition & 3 deletions pypdf/_text_extraction/_layout_mode/_xform_stack.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""manage the PDF transform stack during "layout" mode text extraction"""

from collections import ChainMap, Counter
from typing import ChainMap as ChainMapType
from typing import Counter as CounterType
from typing import Any, Dict, List, Union
from typing import ChainMap as ChainMapType, Counter as CounterType, Any, Dict, List, Union

from .. import mult
from ._fonts import Font, TextStateParams
Expand Down

0 comments on commit 21d9f1b

Please sign in to comment.