Skip to content

Commit

Permalink
Fix circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed May 19, 2022
1 parent c45d11c commit 203306f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
8 changes: 6 additions & 2 deletions PyPDF2/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
RectangleObject,
TextStringObject,
)
from .types import CompressedTransformationMatrix, TransformationMatrixType
from .utils import b_, matrixMultiply
from .utils import (
CompressedTransformationMatrix,
TransformationMatrixType,
b_,
matrixMultiply,
)


def getRectangle(self: Any, name: str, defaults: Iterable[str]) -> RectangleObject:
Expand Down
8 changes: 1 addition & 7 deletions PyPDF2/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Helpers for working with PDF types."""

from typing import List, Tuple, Union
from typing import List, Union

try:
# Python 3.8+: https://peps.python.org/pep-0586
Expand Down Expand Up @@ -31,12 +31,6 @@
# Those go with the FitType: They specify values for the fit
ZoomArgType: TypeAlias = Union[NumberObject, NullObject]
ZoomArgsType: TypeAlias = List[ZoomArgType]
TransformationMatrixType: TypeAlias = Tuple[
Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]
]
CompressedTransformationMatrix: TypeAlias = Tuple[
float, float, float, float, float, float
]

# Recursive types are not yet supported by mypy:
# OutlinesType = List[Union[Destination, "OutlinesType"]]
Expand Down
16 changes: 14 additions & 2 deletions PyPDF2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@

from codecs import getencoder
from io import BufferedReader, BufferedWriter, BytesIO, FileIO
from typing import Any, Dict, Optional, Union, overload
from typing import Any, Dict, Optional, Tuple, Union, overload

try:
# Python 3.10+: https://www.python.org/dev/peps/pep-0484/
from typing import TypeAlias # type: ignore[attr-defined]
except ImportError:
from typing_extensions import TypeAlias # type: ignore[misc]

from .errors import STREAM_TRUNCATED_PREMATURELY, PdfStreamError
from .types import TransformationMatrixType

TransformationMatrixType: TypeAlias = Tuple[
Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]
]
CompressedTransformationMatrix: TypeAlias = Tuple[
float, float, float, float, float, float
]

bytes_type = type(bytes()) # Works the same in Python 2.X and 3.X
StreamType = Union[BytesIO, BufferedReader, BufferedWriter, FileIO]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def test_readUntilRegex_premature_ending_name():
@pytest.mark.parametrize(
("a", "b", "expected"),
[
([[3]], [[7]], [[21]]),
([[3, 7]], [[5], [13]], [[3 * 5.0 + 7 * 13]]),
([[3], [7]], [[5, 13]], [[3 * 5, 3 * 13], [7 * 5, 7 * 13]]),
(((3,),), ((7,),), ((21,),)),
(((3, 7),), ((5,), (13,)), ((3 * 5.0 + 7 * 13,),)),
(((3,), (7,)), ((5, 13),), ((3 * 5, 3 * 13), (7 * 5, 7 * 13))),
],
)
def test_matrixMultiply(a, b, expected):
Expand Down

0 comments on commit 203306f

Please sign in to comment.