From ae93e98f4d601d834cce8fa031979e97be705eb2 Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:35:53 +0000 Subject: [PATCH] STY: Rename local annotation variables (#2984) Make the names of annotation variables more consistent and readable. --- pypdf/_writer.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 138b33724..db779ff49 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -1162,21 +1162,20 @@ def reattach_fields( if "/Annots" not in page: return lst - annots = cast(ArrayObject, page["/Annots"]) - for idx in range(len(annots)): - ano = annots[idx] - indirect = isinstance(ano, IndirectObject) - ano = cast(DictionaryObject, ano.get_object()) - if ano.get("/Subtype", "") == "/Widget" and "/FT" in ano: + annotations = cast(ArrayObject, page["/Annots"]) + for idx, annotation in enumerate(annotations): + is_indirect = isinstance(annotation, IndirectObject) + annotation = cast(DictionaryObject, annotation.get_object()) + if annotation.get("/Subtype", "") == "/Widget" and "/FT" in annotation: if ( - "indirect_reference" in ano.__dict__ - and ano.indirect_reference in fields + "indirect_reference" in annotation.__dict__ + and annotation.indirect_reference in fields ): continue - if not indirect: - annots[idx] = self._add_object(ano) - fields.append(ano.indirect_reference) - lst.append(ano) + if not is_indirect: + annotations[idx] = self._add_object(annotation) + fields.append(annotation.indirect_reference) + lst.append(annotation) return lst def clone_reader_document_root(self, reader: PdfReader) -> None: