From 809e0a34b2370bfad51e8f7b9e559bf759452dc7 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sun, 29 Oct 2023 05:21:54 +0100 Subject: [PATCH 1/2] MAINT: Apply pre-commit hooks --- pypdf/_writer.py | 15 ++++----------- pypdf/generic/_data_structures.py | 4 +++- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 8f365cf60..10cc9342a 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -2218,18 +2218,12 @@ def clean(content: ContentStream, images: List[str], forms: List[str]) -> None: if ( ( operator == b"INLINE IMAGE" - and ( - cast(ObjectDeletionFlag, to_delete) - & ObjectDeletionFlag.INLINE_IMAGES - ) + and (to_delete & ObjectDeletionFlag.INLINE_IMAGES) ) or (operator in jump_operators) or ( operator == b"Do" - and ( - cast(ObjectDeletionFlag, to_delete) - & ObjectDeletionFlag.XOBJECT_IMAGES - ) + and (to_delete & ObjectDeletionFlag.XOBJECT_IMAGES) and (operands[0] in images) ) ): @@ -2256,8 +2250,7 @@ def clean_forms( try: content: Any = None if ( - to_delete - & ObjectDeletionFlag.XOBJECT_IMAGES + to_delete & ObjectDeletionFlag.XOBJECT_IMAGES and o["/Subtype"] == "/Image" ): content = NullObject() # to delete the image keeping the entry @@ -2314,7 +2307,7 @@ def remove_images( Remove images from this output. Args: - to_delete : The type of images to be deleted + to_delete : The type of images to be deleted (default = all images types) ignore_byte_string_object: deprecated """ diff --git a/pypdf/generic/_data_structures.py b/pypdf/generic/_data_structures.py index ff1dfb676..f886314d8 100644 --- a/pypdf/generic/_data_structures.py +++ b/pypdf/generic/_data_structures.py @@ -293,7 +293,9 @@ def _clone( except Exception: cur_obj = None for s, c in objs: - c._clone(s, pdf_dest, force_duplicate, ignore_fields, visited) + c._clone( + s, pdf_dest, force_duplicate, ignore_fields, visited + ) for k, v in src.items(): if k not in ignore_fields: From 224e0da90ea1f8e37248fbc96cc9a080573cd5f4 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sun, 29 Oct 2023 05:31:08 +0100 Subject: [PATCH 2/2] Add comment --- pypdf/generic/_data_structures.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pypdf/generic/_data_structures.py b/pypdf/generic/_data_structures.py index f886314d8..4ee13a13b 100644 --- a/pypdf/generic/_data_structures.py +++ b/pypdf/generic/_data_structures.py @@ -188,7 +188,7 @@ def clone( except Exception: pass - visited: Set[Tuple[int, int]] = set() + visited: Set[Tuple[int, int]] = set() # (idnum, generation) d__ = cast( "DictionaryObject", self._reference_clone(self.__class__(), pdf_dest, force_duplicate), @@ -205,7 +205,7 @@ def _clone( pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Optional[Sequence[Union[str, int]]], - visited: Set[Tuple[int, int]], + visited: Set[Tuple[int, int]], # (idnum, generation) ) -> None: """ Update the object from src.