@@ -352,11 +352,10 @@ def get_num_pages(self) -> int:
352352 # the original method (flattened page count) is used.
353353 if self .is_encrypted :
354354 return self .root_object ["/Pages" ]["/Count" ] # type: ignore
355- else :
356- if self .flattened_pages is None :
357- self ._flatten (self ._readonly )
358- assert self .flattened_pages is not None
359- return len (self .flattened_pages )
355+ if self .flattened_pages is None :
356+ self ._flatten (self ._readonly )
357+ assert self .flattened_pages is not None
358+ return len (self .flattened_pages )
360359
361360 def get_page (self , page_number : int ) -> PageObject :
362361 """
@@ -585,16 +584,15 @@ def get_fields(
585584 def _get_qualified_field_name (self , parent : DictionaryObject ) -> str :
586585 if "/TM" in parent :
587586 return cast (str , parent ["/TM" ])
588- elif "/Parent" in parent :
587+ if "/Parent" in parent :
589588 return (
590589 self ._get_qualified_field_name (
591590 cast (DictionaryObject , parent ["/Parent" ])
592591 )
593592 + "."
594593 + cast (str , parent .get ("/T" , "" ))
595594 )
596- else :
597- return cast (str , parent .get ("/T" , "" ))
595+ return cast (str , parent .get ("/T" , "" ))
598596
599597 def _build_field (
600598 self ,
@@ -713,12 +711,11 @@ def get_form_text_fields(self, full_qualified_name: bool = False) -> Dict[str, A
713711 def indexed_key (k : str , fields : Dict [Any , Any ]) -> str :
714712 if k not in fields :
715713 return k
716- else :
717- return (
718- k
719- + "."
720- + str (sum (1 for kk in fields if kk .startswith (k + "." )) + 2 )
721- )
714+ return (
715+ k
716+ + "."
717+ + str (sum (1 for kk in fields if kk .startswith (k + "." )) + 2 )
718+ )
722719
723720 # Retrieve document form fields
724721 formfields = self .get_fields ()
@@ -759,12 +756,11 @@ def get_pages_showing_field(
759756 def _get_inherited (obj : DictionaryObject , key : str ) -> Any :
760757 if key in obj :
761758 return obj [key ]
762- elif "/Parent" in obj :
759+ if "/Parent" in obj :
763760 return _get_inherited (
764761 cast (DictionaryObject , obj ["/Parent" ].get_object ()), key
765762 )
766- else :
767- return None
763+ return None
768764
769765 try :
770766 # to cope with all types
@@ -824,7 +820,7 @@ def open_destination(
824820 oa = oa .decode ()
825821 if isinstance (oa , str ):
826822 return create_string_object (oa )
827- elif isinstance (oa , ArrayObject ):
823+ if isinstance (oa , ArrayObject ):
828824 try :
829825 page , typ , * array = oa
830826 fit = Fit (typ , tuple (array ))
@@ -907,8 +903,7 @@ def threads(self) -> Optional[ArrayObject]:
907903 catalog = self .root_object
908904 if CO .THREADS in catalog :
909905 return cast ("ArrayObject" , catalog [CO .THREADS ])
910- else :
911- return None
906+ return None
912907
913908 @abstractmethod
914909 def _get_page_number_by_indirect (
@@ -961,18 +956,17 @@ def _build_destination(
961956 ):
962957 page = NullObject ()
963958 return Destination (title , page , Fit .fit ())
964- else :
965- page , typ , * array = array # type: ignore
966- try :
967- return Destination (title , page , Fit (fit_type = typ , fit_args = array )) # type: ignore
968- except PdfReadError :
969- logger_warning (f"Unknown destination: { title } { array } " , __name__ )
970- if self .strict :
971- raise
972- # create a link to first Page
973- tmp = self .pages [0 ].indirect_reference
974- indirect_reference = NullObject () if tmp is None else tmp
975- return Destination (title , indirect_reference , Fit .fit ())
959+ page , typ , * array = array # type: ignore
960+ try :
961+ return Destination (title , page , Fit (fit_type = typ , fit_args = array )) # type: ignore
962+ except PdfReadError :
963+ logger_warning (f"Unknown destination: { title } { array } " , __name__ )
964+ if self .strict :
965+ raise
966+ # create a link to first Page
967+ tmp = self .pages [0 ].indirect_reference
968+ indirect_reference = NullObject () if tmp is None else tmp
969+ return Destination (title , indirect_reference , Fit .fit ())
976970
977971 def _build_outline_item (self , node : DictionaryObject ) -> Optional [Destination ]:
978972 dest , title , outline_item = None , None , None
0 commit comments