@@ -979,13 +979,13 @@ def update_page_form_field_values(
979979 logger_warning ("No fields to update on this page" , __name__ )
980980 return
981981 for annotation in page [PG .ANNOTS ]: # type: ignore
982- annotation = cast (DictionaryObject , annotation .get_object ())
983- if annotation .get ("/Subtype" , "" ) != "/Widget" :
982+ annotation_obj = cast (DictionaryObject , annotation .get_object ())
983+ if annotation_obj .get ("/Subtype" , "" ) != "/Widget" :
984984 continue
985- if "/FT" in annotation and "/T" in annotation :
986- parent_annotation = annotation
985+ if "/FT" in annotation_obj and "/T" in annotation_obj :
986+ parent_annotation = annotation_obj
987987 else :
988- parent_annotation = annotation .get (
988+ parent_annotation = annotation_obj .get (
989989 PG .PARENT , DictionaryObject ()
990990 ).get_object ()
991991
@@ -1098,17 +1098,17 @@ def reattach_fields(
10981098 annotations = cast (ArrayObject , page ["/Annots" ])
10991099 for idx , annotation in enumerate (annotations ):
11001100 is_indirect = isinstance (annotation , IndirectObject )
1101- annotation = cast (DictionaryObject , annotation .get_object ())
1102- if annotation .get ("/Subtype" , "" ) == "/Widget" and "/FT" in annotation :
1101+ annotation_obj = cast (DictionaryObject , annotation .get_object ())
1102+ if annotation_obj .get ("/Subtype" , "" ) == "/Widget" and "/FT" in annotation_obj :
11031103 if (
1104- "indirect_reference" in annotation .__dict__
1105- and annotation .indirect_reference in fields
1104+ "indirect_reference" in annotation_obj .__dict__
1105+ and annotation_obj .indirect_reference in fields
11061106 ):
11071107 continue
11081108 if not is_indirect :
1109- annotations [idx ] = self ._add_object (annotation )
1110- fields .append (annotation .indirect_reference )
1111- lst .append (annotation )
1109+ annotations [idx ] = self ._add_object (annotation_obj )
1110+ fields .append (annotation_obj .indirect_reference )
1111+ lst .append (annotation_obj )
11121112 return lst
11131113
11141114 def clone_reader_document_root (self , reader : PdfReader ) -> None :
@@ -1469,8 +1469,10 @@ def _write_pdf_structure(self, stream: StreamType) -> tuple[list[int], list[int]
14691469 object_positions .append (stream .tell ())
14701470 stream .write (f"{ idnum } 0 obj\n " .encode ())
14711471 if self ._encryption and obj != self ._encrypt_entry :
1472- obj = self ._encryption .encrypt_object (obj , idnum , 0 )
1473- obj .write_to_stream (stream )
1472+ obj_to_write = self ._encryption .encrypt_object (obj , idnum , 0 )
1473+ else :
1474+ obj_to_write = obj
1475+ obj_to_write .write_to_stream (stream )
14741476 stream .write (b"\n endobj\n " )
14751477 else :
14761478 object_positions .append (- 1 )
@@ -1560,8 +1562,10 @@ def add_metadata(self, infos: dict[str, Any]) -> None:
15601562 infos = cast (DictionaryObject , infos .get_object ())
15611563 for key , value in list (infos .items ()):
15621564 if isinstance (value , PdfObject ):
1563- value = value .get_object ()
1564- args [NameObject (key )] = create_string_object (str (value ))
1565+ value_obj = value .get_object ()
1566+ else :
1567+ value_obj = value
1568+ args [NameObject (key )] = create_string_object (str (value_obj ))
15651569 if self ._info is None :
15661570 self ._info = DictionaryObject ()
15671571 self ._info .update (args )
0 commit comments